標籤:
1,distinct 對某一列進行去重檢索有職工的工資大於或等於wh1倉庫中任何一名職工工資的倉庫號select distinct cno from zhigongbiao where gongzi >= (select Min(gongzi) from zhigongbiao where cno in (‘wh1‘))2 ,between and 在...之間檢索出工資在1220元到1240元範圍內的職工資訊。select *from zhigongbiao where gongzi between 1220 and 12403,order by desc ,asc 將一列進行升序或降序排列先按倉庫號排序,再按工資排序並輸出全部職工資訊select*from zhigongbiao order by cno asc,gongzi desc4,join on 表串連,表示橫向表串連找出工作在面積大於400的倉庫的職工號以及這些職工工作所在的城市select zno ,city from cangkubiao join zhigongbiao on cangkubiao.cno=zhigongbiao .cno where mianji>4005, union 表串連,表示縱向錶鏈接union 中的所有挑選清單必須具有相同的列數,相似的資料類型和相同的順序結果集中的列名來自第一個select 語句6, 相互關聯的子查詢, 列出每個職工經手的具有最高總金額的訂購單資訊 --重點題目,相互關聯的子查詢 select*from dingdanbiao a where dingdanzongjia not in (select MAX(dingdanzongjia) from dingdanbiao b where a.zno=b.zno) 7, 彙總函式count ,avg ,sum, max,min 8,group by 對制定列進行分組 having 在分組的基礎上進行進一步篩選,一般與 group by 子句配合使用 求至少有兩個職工的每個倉庫的平均工資select cno,AVG (gongzi) 平均工資 from zhigongbiao group by cno having COUNT(*)>=19,子查詢(巢狀查詢)使用查詢語句查詢一列資料出來,然後作為其他查詢條件中參數來使用檢索有職工的工資大於或等於wh1倉庫中所有職工工資的倉庫號。select cno from zhigongbiao where gongzi >=(select Max(gongzi) from zhigongbiao where cno in (‘wh1‘))10, 時間和日期函數datediff 功能是擷取兩個日期之間的值查詢Student表中每個學生的姓名和年齡。select sname,DATEDIFF(YEAR,sbirthdy,getdate()) age from studentday(date),取指定日期的日 month(date),取制定日期的月 year(date) 取制定日期的年查詢和學號為3的同學同年出生的所有學生的Sno、Sname和Sbirthday列。 --重點題目select sno,sname,sbirthdy from student where YEAR(sbirthdy)=(select YEAR(sbirthdy)from student where sno=‘3‘)11,in ,like,=,>,< 等,還有 top 子句,查詢前幾行 查詢Score表中的最高分的學生學號和課程號。(子查詢或者排序)select sno,cno from score where degree=(select MAX(degree) from score)select top 1* sno,cno from score order by degree desc
SQL Server 具體查詢要點,自己整理