1. 程式人生 > >order by 和 ground by 區別:

order by 和 ground by 區別:

order by 排序查詢:asc升序 desc降序 select * from Student order by age根據學生的年齡查詢學生資訊(預設是升序) ground by:分組查詢 having只能用於ground by子句作用於組內

  1. 按照學號分組查詢每個學號的總成績 select 學號, SUM(成績) from 選課表 ground by 學號
  2. 查詢平均成績大於001課程平均成績的學號並按平均成績的降序排列 select 學號,SUM(成績) from 成績表 ground by 學號 having AVG(成績) >(select AVG(成績) from 選課表 where 課程號=‘001’) order by AVG(成績) desc;