有个表pages ,有5个属性,id, url, title, body, site.
问: 用一条SQL语句搜出url,body,或site中包含’test’字符串的数据,且将含有‘test’的url 的结果放在最前面,其次是body, 然后是site 且不能有重复数据
如:
id url title body site
1 'a' 'b' 'c' 'd'
2 'a' 'b' 'c' 'test'
3 'a' 'b' 'test' 'd'
4 'ftest' 'b' 'c' 'd'
5 'test' 'b' 'test' 'test'
搜出的结果是:
id url title body site
4 'ftest' 'b' 'c' 'd'
5 'test' 'b' 'test' 'test'
3 'a' 'b' 'test' 'd'
2 'a' 'b' 'c' 'test'
问: 用一条SQL语句搜出url,body,或site中包含’test’字符串的数据,且将含有‘test’的url 的结果放在最前面,其次是body, 然后是site 且不能有重复数据
如:
id url title body site
1 'a' 'b' 'c' 'd'
2 'a' 'b' 'c' 'test'
3 'a' 'b' 'test' 'd'
4 'ftest' 'b' 'c' 'd'
5 'test' 'b' 'test' 'test'
搜出的结果是:
id url title body site
4 'ftest' 'b' 'c' 'd'
5 'test' 'b' 'test' 'test'
3 'a' 'b' 'test' 'd'
2 'a' 'b' 'c' 'test'
解决方案 »
- 数据库中某个字段会莫名的变成空值,该怎么监视这个字段呢?
- mysql在windows下如何安装,求详细步骤!
- mysql查表记录合并
- 为什么创建用户后,phpmyadmin不能进入MySQL的数据库?
- 公司数据库用MYSQL,大家给点资料,帮帮我呀
- 我的表名叫a-b,在linux的shell下用(drop table a-b)删除时,报错,请问怎么办
- 如果在mysql的一个数据库中添加数万个甚至是几百万个表效率和稳定性如何?
- 各位牛人老大,关于postgres的一点菜问题,进来帮帮忙呀分数我一次只能给这么多会再给分的!
- sql中如何判断一个id下出现两次以上某字段的值
- MySQL官方手册,下载地址?
- 用一个SQL语句不知道能否实现这个功能?
- MYSQL存储过程字符串参数问题
from table
where url like '%test'
or body like '%test'
or site like '%test'
order by url like '%test' desc,
body like '%test' desc,
site like '%test'
distinct 与 × 是不能同时用的,谢谢!
http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
去看看