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
......
用MYSQL语句:
mysql -uroot -p^^^^^ -e "select * from test.table2" > d:\a.xls
其中test为数据库 table2为其中的表 d:\a.xls为表位置 ......
query_cache_min_res_unit 查询缓存分配的最小块的大小(字节)
query_alloc_block_size 为查询分析和执行过程中创建的对象分配的内存块大小
Qcache_free_blocks代表内存自由块的多少,反映了内存碎片的情况
==========================
1)当查询进行的时候,Mysql把查询结果保存在qurey ......
(1)INFORMATION_SCHEMA
select (sum(data_length) + sum(index_length))/(1024*1024) from INFORMATION_SCHEMA.`TABLES` where table_schema = 'your_table_schema' and table_name like 'your_table_name';
(2)show table status like '';
try {
Class.forName("com.mysql.jdbc.Driver");
......
MySQL的字符集支持(Character Set Support)有两个方面:
字符集(Character set)和排序方式(Collation)。
对于字符集的支持细化到四个层次:
服务器(server),数据库(database),数据表(table)和连接(connection)。
1.MySQL默认字符集
MySQL对于字符集的 ......