21-8 数据检索2 top和distinct
生活随笔
收集整理的這篇文章主要介紹了
21-8 数据检索2 top和distinct
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
--distinct關鍵字,根據已經查詢出的結果然后去除重復
select distinct * from TblStudent --Top(一般會配合order by一起使用)
---------------------排序--------------------------
--order by 列名 --按照年齡,降序排序
select * from TblStudent order by tsAge desc --降序排序
--按照年齡,升序排序
select * from TblStudent order by tsAge asc--升序排序
select * from TblStudent order by tsAge --默認就是升序排序 --查詢數學成績最高的前5名
select top 5 * from TblStudent order by tmath desc
--查詢數學成績最低的前5名
select top 5 * from TblStudent order by tmath asc --如果top后跟的不是一個數字,而是一個表達式,一定要使用()把表達式括起來
select top (2*2) * from TblStudent order by tmath desc --會查詢出4條數據(向上取整)
select top 35 percent * from TblStudent order by tmath desc --獲得年紀最小的5個學生
select top 5 *from TblStudent order by tsage asc --獲得年紀最大的10%的學生(percent)
select top 10 percent * from Tblstudent order by tsage desc
總結
以上是生活随笔為你收集整理的21-8 数据检索2 top和distinct的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [洛谷P3948]数据结构
- 下一篇: 双层培养摇床:应用领域、使用方法与维护要