首页 新闻 赞助 找找看

非常实用的查询需求,这样的SQL 怎么写??

0
悬赏园豆:20 [已关闭问题]

Book表结构:book(id(int,key),title(varchar(50)),content(varchar(500)))
要求查询:title或content中包含 字符串'china'的记录集合,并要求符合title的记录集排在前面,符合content条件的记录排在后面。

求SQL ? !

kevin@的主页 kevin@ | 初学一级 | 园豆:130
提问于:2010-04-22 09:18
< >
分享
其他回答(3)
0

select * from book where title like '%china%'

union

select * from book where content like '%china%'

Gray Zhang | 园豆:17610 (专家六级) | 2010-04-22 09:20
0

如果表记录多的话,like会引起全表扫描,建议使用全文索引。

Astar | 园豆:40805 (高人七级) | 2010-04-22 09:25
0

select * from book where charindex('china',title)>0

union all

select * from book where charindex('china',content)>0

清海扬波 | 园豆:825 (小虾三级) | 2010-04-22 12:00
0

select * from book where charindex('china',title)>0
or charindex('china',content)>0
order by charindex('china',title) desc

快速开发平台 | 园豆:177 (初学一级) | 2010-04-22 15:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册