求写一条sql语句?

有一张数据表pages(id,title,body,url,site)用一条sql语句查询出title或body或url中含有字符'test',先匹配title,其次是body,最后才是url,且同一条记录只能显示一次。请问这条sql语句怎么写?

select '所有title匹配的' as 分组, * from pages where title like '%test%'
union
select '所有body匹配的' as 分组, * from pages where body like '%test%' and not(title like '%test%')
union
select '所有url匹配的' as 分组, * from pages where url like '%test%' and not(title like '%test%') and not(body like '%test%')

按我的理解,这样是可以的啊,至于分组那列是我自己随便加的,说明文字也是随意写的,不需要可以去掉的。

select * from pages where (title like '%test%') or (body like '%test%') or (url like '%test%')

我觉得 love_ai87 的回答
select * from pages where (title like '%test%') or (body like '%test%') or (url like '%test%')
是对的啊

可能是你没有把问题说清楚到底是要一种什么样的结果,就是你说的分组,怎么分?

这样行吗?

select 'title包含test' as 分组, * from pages where title like '%test%'
union
select 'body包含test 并且 title不包含test' as 分组, * from pages where body like '%test%' and not(title like '%test%')
union
select 'url包含test 并且 title不包含test 并且 body不包含test' as 分组, * from pages where url like '%test%' and not(title like '%test%') and not(body like '%test%')