SQL Server 具體查詢要點,自己整理

來源:互聯網
上載者:User

標籤:

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 具體查詢要點,自己整理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.