有个表pages ,有5个属性,id, url, title, body, site.
问: 用一条SQL语句搜出url,body,或site中包含’test’字符串的数据,且将含有‘test’的url 的结果放在最前面,其次是body, 然后是site 且不能有重复数据
如:
id url title body site
1 'a' 'b' 'c' 'd'
2 'a' 'b' 'c' 'test'
3 'a' 'b' 'test' 'd'
4 'ftest' 'b' 'c' 'd'
5 'test' 'b' 'test' 'test'
搜出的结果是:
id url title body site
4 'ftest' 'b' 'c' 'd'
5 'test' 'b' 'test' 'test'
3 'a' 'b' 'test' 'd'
2 'a' 'b' 'c' 'test'

解决方案 »

  1.   

    select distinct *
    from table
    where url like '%test'
    or body like '%test'
    or site like '%test'
    order by url like '%test' desc,
    body like '%test' desc,
    site like '%test'
      

  2.   

    不知道你把代码贴出来前,有没有自己实验过一下呢----有点不负责哦。
    distinct 与 × 是不能同时用的,谢谢!
      

  3.   

    一般不试验。回答主要是提供思路,除非那个贴子的楼主直接提供create table .. insert into ..语句,否则自己还要构造这些表。一般来说CSDN上懒人还是居多的。
      

  4.   

    除非如下的贴子,测试的人会多一些。另外一种就给分极高的帖子。
    http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
      

  5.   

    http://topic.csdn.net/u/20100625/21/cb7295e6-0514-4e28-888f-2935537208f4.html
    去看看