比如一张学生成绩表中有三个字段,人名,数学成绩,语文成绩,要求查出数学成绩大于60,语文成绩小于60的所有人,并且要求查询结果先是数学成绩大于60的所有人,后面在是跟着语文成绩小于60的所有人的数据,也就是排在前面的人都是数学成绩大于60的人排在后面的都是语文成绩小于60的人.
如何查啊
 

解决方案 »

  1.   

    SELECT 人名,数学成绩,语文成绩 FROM 表名 WHERE 数学成绩>60
    UNION
    SELECT 人名,数学成绩,语文成绩 FROM 表名 WHERE 语文成绩<60
      

  2.   

    SQL>    select *
      2       from (
      3            select 'aa' as name,80 as mathsScore,50 as yuwenScore from dual
      4            union all
      5            select 'bb' as name,40 as mathsScore,70 as yuwenScore from dual
      6            union all
      7            select 'cc' as name,30 as mathsScore,70 as yuwenScore from dual
      8            union all
      9            select 'dd' as name,80 as mathsScore,50 as yuwenScore from dual
     10            union all
     11            select 'ee' as name,90 as mathsScore,35 as yuwenScore from dual
     12            union all
     13            select 'ff' as name,10 as mathsScore,10 as yuwenScore from dual
     14            )tt
     15      where tt.mathsScore > 60
     16        or tt.yuwenScore < 60
     17       order by tt.mathsScore desc;NAME MATHSSCORE YUWENSCORE
    ---- ---------- ----------
    ee           90         35
    aa           80         50
    dd           80         50
    ff           10         10
      

  3.   

    非常感谢mantisXF,但是还是没有解决我的问题,我实际中遇到的问题是一张表中有区号和邮政编码两个字段,他们都是varchar2型,并用like条件去查询符合区号和邮政编码的数据.
    区号和邮政编码这样排序还是混乱的,不能先是符合区号的数据在前,符合邮政编码的数据在后.
    还有别的写法吗?
      

  4.   

    SELECT 人名,数学成绩,语文成绩 FROM 表名 WHERE 数学成绩>60 and 语文成绩<60 order by 数学成绩 desc;
      

  5.   

    select 字段**,區號,郵政編碼 from 表名 where 區號 like '%條件1%' or 郵政編碼 like '%條件2%' order by 區號,郵政編碼
      

  6.   

    Sooch 停止吹牛了,你的那个 tengyunjiawu.net 什么时候停掉?
    不会还继续宣传是你自己做的吧?不过我猜你一定特别喜欢http://www.java2s.com/
    不然怎么抄袭人家的内容连接到自己的网站呢?
    看更多更详尽的内容,请到http://www.java2s.com/