【文章內(nèi)容簡介】
nme相當(dāng)于做笛卡兒積,如查詢李山的同鄉(xiāng):select * from students where native in(select native from students where name=’ 李山’),比如,下面兩句是等價的:select * from students where sno in(select sno from grades where o=’B2’)select * from students where exists(select * from grades where = AND o=’B2’),有兩種方法:asc升序和desc降序,可以按照查詢條件中的某項(xiàng)排列,而且這項(xiàng)可用數(shù)字表示,如:select sno,count(*),avg(mark)from grades group by sno having avg(mark)85 order by 3 ,應(yīng)該用“[]”括住。,如: select sno, courseno from grades where mark IS NULL,any相當(dāng)于邏輯運(yùn)算“||”而all則相當(dāng)于邏輯運(yùn)算“amp。amp?!保喝?,沒有選修‘B2’課程的學(xué)生 :select students.* from students, grades where = AND ’B2’上面的查詢方式是錯誤的,正確方式見下方:select * from students where not exists(select * from grades where = AND o=39。B239。):如,選修了全部課程的學(xué)生:select * from students where not exists(select * from courses where NOT EXISTS(select * from grades where sno= AND o=))最外一重:從學(xué)生表中選,排除那些有課沒選的。用not exist。由于討論對象是課程,所以第二重查詢從course表中找,排除那些選了課的即可。第三篇:幾個簡單的基本的sql語句幾個簡單的基本的sql語句(1)數(shù)據(jù)記錄篩選:sql=“select * from 數(shù)據(jù)表 where 字段名=字段值 order by 字段名[desc]”sql=“select * from 數(shù)據(jù)表 where 字段名 like 39。%字段值%39。 order by 字段名 [desc]”sql=“select top 10 * from 數(shù)據(jù)表 where 字段名 order by 字段名[desc]”sql=“select * from 數(shù)據(jù)表 where 字段名 in(39。值139。,39。值239。,39。值339。)”sql=“select * from 數(shù)據(jù)表 where 字段名 between 值1 and 值2”(2)更新數(shù)據(jù)記錄:sql=“update 數(shù)據(jù)表 set 字段名=字段值 where 條件表達(dá)式”sql=“update 數(shù)據(jù)表 set 字段1=值1,字段2=值2 …… 字段n=值n where 條件表達(dá)式”(3