mysql中INSTR函数的用法
mysql中INSTR函数的用法
INSTR(字段名, 字符串)
这个函数返回字符串在某一个字段的内容中的位置, 没有找到字符串返回0,否则返回位置(从1开始)
SELECT * from tblTopic ORDER BY INSTR( topicTitle, 'ha' ) > 0 DESC
SELECT INSTR( topicTitle, 'ha' ) from tblTopic
mysql中使用instr配合IN排序
将instr结果作为一列,按其排序
select id,1 from world_guide where id = 32
union
select * from
(select id, instr('30,35,31,',id+',') as d from
world_blog where id in (30,35,31) order by d) as t;
输出
+----+---+
| id | 1 |
+----+---+
| 32 | 1 |
| 30 | 1 |
| 35 | 4 |
| 31 | 7 |
+----+---+
4 rows in set, 6 warnings (0.02 sec)
表A
字段:姓名 name
张三
王五
表B
字段:标题 title
信息一 张三发布
信息二 王五发布
信息三 张三发布
排行榜,按表A的姓名 like %‘name’% 匹配 表B的 title 的条数进行排序,
排行榜样例
张三 2
王五 1
select 姓名,count(b.title) from a inner join b on instr(b.title,a.姓名)>0
group by 姓名
order by count(b.title)
select name,(select count(*) from 表B where instr(title,表A.name)
from 表A
order by 2 desc
相关文档:
1.DATE_FORMAT('2010-05-15 15:47:36','%H:%i:%s') -> 结果:15:47:36
将日期格式根据条件不同转换成所需要的日期、时间格式
2.timediff('23:40:00', ' 18:30:00') -> 结果:05:10:00
......
1.建表过程如下
create database test default character set utf8 collate utf8_general_ci
use test;
create table devicedata
(
ID int auto_increment PRIMARY key ,
TimeStamp datetime,
Device_Name varchar(100),
Tag_Name varchar(100),
Value varchar(50)
)
2 ......
CREATE PROCEDURE pro_page(
in _sql varchar(1000),
in _order varchar(1000),
in _pagecurrent int,
in _pagesize int
)
BEGIN
if _pagesize<=1 then
set _pagesize=20;
end if;
if _pagecurrent < 1 then
set _pagecurrent = 1;
&n ......
1、打开文本编辑my.cnf
sudo gedit /etc/mysql/my.cnf
在[client]
节点,添加
default-character-set=utf8 (客户端缺省以utf8存储)
在[mysqld]
节点,添加
default-character-set=utf8 (数据库缺省以utf8存储)
init_connect='SET NAMES utf8'
(设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8 ......