1.查詢排序:order by asc(升序)或desc(降序),默認asc(升序)
查詢選修了 3號課程的學生的學號及其成績,查詢結果按分數的降序排列。
select sno,score from sc where cno='c3' order by score desc
查詢全體學生情況,查詢結果按所在系升序排列。
select * from s order by dept asc
查詢全體學生情況,對同一系中的學生按年齡降序排序。
select * from s order by 4 desc --"4"表示"select *"查詢列中的第四列
查詢全體學生情況,查詢結果按所在系升序排列,對同一系中的學生按年齡降序排序.
select * from s order by dept,4 desc --"4"表示"select *"查詢列中的第四列.默認asc(升序)
2.分組查詢 group by:
將查詢結果表的各行按一列或多列取值相等的原則進行分組。
例:查詢各個課程號與相應的選課人數。
select cno,count(sno) from sc group by cno
分組后還要求按一定的條件對這些組進行篩選,最終只輸出滿足指定條件組的統計值,可以使用having 子句
例:查詢有五人以上學生選修的課程號及選修人數。
select cno,count(sno) from sc group by cno having count(*)>=2
數據庫表s,c,sc截圖請到:http://www.cnblogs.com/fuge/archive/2012/03/16/2400913.html