问一条级难的SQL语句!疯了```
ID URL TITLE BODY
1 WWW.BAIDU.COM ******* ********
2 WWW.SINA.COM.CN ******* ********
3 WWW.SOHU.COM ******* ********
要求:比如查询“BAIDU”,在URL中有就先返回,在TITLE中有就第二个返回,在BODY中有就第三返回。类似搜索引擎!都没有就不返回。
------解决方案--------------------呵呵,我也遇到过,是建立一张视图搞定的
然后在把该表和视图一起查询实现的
------解决方案--------------------分别查询呗
------解决方案--------------------不考虑效率
select * from where url like '%BAIDU% '
union
.... where title like ...
union
.... where body like ...
------解决方案--------------------分成三个查询,把结果联合在一起
select ..... union select ...... union select .......
------解决方案--------------------select id,c from
(
select id,url as c from table
union
select id,title as c from table
union
select id,body as c from table
) exp1
where c like= 'baidu ' order by id