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
相关文档:
先按照下面的表结构创建mysql_order_by_test数据表,我们用实例一点一点告诉你,MySQL order by的用法。
ORDER BY uid ASC
按照uid正序查询数据,也就是按照uid从小到大排列
ORDER BY uid DESC
按照uid逆序查询数据,也就是按照uid从大到小排列
我们来看
SELECT * from mysql_order_by_test OR ......
用MYSQL语句:
mysql -uroot -p^^^^^ -e "select * from test.table2" > d:\a.xls
其中test为数据库 table2为其中的表 d:\a.xls为表位置 ......
#!/bin/bash
#删除100个数据库中的1000个表的过期数据
DBHOST="127.0.0.1"
DBPWD="pwd"
DBUSER="root"
MYSQLBIN="/usr/local/mysql/bin/mysql"
for((dbindex = 0;dbindex < 100;dbindex++))
do
for((tabindex = 0;tabindex < 10;tabindex++))
do
if [&n ......
作者 小荷||【转载时请务必以超链接形式标明文章原始出处和作者信息】
· 永久链接: http://www.oracleblog.cn/useful-script/prompt-of-sqlplus/
misc@ORALOCAL(192.168.0.49)>
如果你也想和我一样,在sqlplus登录数据库的时候,能提示不少像上面这样详细登录的信息:
1.登录的用户名。当你的数据库中有多个 ......
格式:grant [PRIVILEGES] on [databaseName.tableName] to [userName]@[host] identified by [password] with grant option;
eg1: grant select on mysql.user to wqh@localhost
eg2:GRANT SELECT,INSERT,UPDATE,DELETE,CREATE ......