9.關于排序order
a.對于排序order,有兩種方法:asc升序和desc降序
b.對于排序order,可以按照查詢條件中的某項排列,而且這項可用數(shù)字表示,如:
select sno,count(*) ,avg(mark) from grades
group by sno
having avg(mark)>85
order by 3
10.其他
a.對于有空格的識別名稱,應該用"[]"括住。
b.對于某列中沒有數(shù)據(jù)的特定查詢可以用null判斷,如select sno,courseno from grades where mark IS NULL
c.注意區(qū)分在嵌套查詢中使用的any與all的區(qū)別,any相當于邏輯運算“||”而all則相當于邏輯運算“&&”
d.注意在做否定意義的查詢是小心進入陷阱:
如,沒有選修‘B2’課程的學生 :
select students.*
from students, grades
where students.sno=grades.sno
AND grades.cno <> ’B2’
上面的查詢方式是錯誤的,正確方式見下方:
select * from students
where not exists (select * from grades
where grades.sno=students.sno AND cno='B2')
11.關于有難度多重嵌套查詢的解決思想:
如,選修了全部課程的學生:
select *
from students
where not exists ( select *
from courses
where NOT EXISTS
(select *
from grades
where sno=students.sno
AND cno=courses.cno))
最外一重:從學生表中選,排除那些有課沒選的。用not exist。由于討論對象是課程,所以第二重查詢從course表中找,排除那些選了課的即可。
希望與更多計算機等級考試的網(wǎng)友交流,請進入計算機等級考試論壇
更多信息請訪問:考試吧計算機等級考試欄目
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內蒙古 |