首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

SQL

2012-02-13 
SQL求助sql小测试:有张表pages 列:id , url , content , body类型:id --int 后面3个varchar现在要求查询:u

SQL求助
sql小测试:有张表pages 列:id , url , content , body  
类型:id --int 后面3个varchar
现在要求查询:url 中包含google字符串的显示在最上面,body的显示在中间,content的显示在最下面,请使用一条语句查询!


[解决办法]

SQL code
select * from pages where id in ( -- get all records   select distinct id from pages where id in ( --remove duplicate records     select id from pages where url like '%google%' --url contains 'google'     union all      select id from pages where content like '%google%'  --content contains 'google'     union all      select id from pages where body like '%google%'  --body contains 'google'   ))
[解决办法]
SQL code
select url,body,content       decode(instr(url, 'google'),              0,              decode(instr(body, 'google'),                     0,                     decode(instr(content, 'google'), 0, 4, 3),                     2),              1) type_order  from pages  order by type_order 

热点排行