SQL求助

杀猪剑客 2011-10-08 02:07:38
sql小测试:有张表pages 列:id , url , content , body
类型:id --int 后面3个varchar
现在要求查询:url 中包含google字符串的显示在最上面,body的显示在中间,content的显示在最下面,请使用一条语句查询!
...全文
110 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
杀猪剑客 2011-10-18
  • 打赏
  • 举报
回复
可以用union all 来做!
(select id from pages p where p.url="google") union all (select id from pages p where p.body = "google") union all (select id from pages p where p.content = "google");
SasONsoft 2011-10-08
  • 打赏
  • 举报
回复
mark,回来再看~
gukuitian 2011-10-08
  • 打赏
  • 举报
回复

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
tastypinenut 2011-10-08
  • 打赏
  • 举报
回复
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'
)
)
luckyzhangye 2011-10-08
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
看了才发现,我觉的挺难

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧