數據檢索

-------------------------------數據檢索-----------------------------------
use Itcast2014
select * from Orders
select OrderID,CustomerID,EmployeeID from Orders
-------------------起列名------------
select
 OrderID as 訂單編號,
 CustomerID as 用戶編號,
 EmployeeID
from Orders
-----------------------2-------------
select
 OrderID '訂單  編號',
 CustomerID 用戶編號,
 EmployeeID
from Orders
-----------------------3-------------
select
 訂單編號 = OrderID,
 用戶編號 = CustomerID,
 EmployeeID
from Orders
-------------------獲取服務器的當前時間---------------------
select GETDATE()

select 1+2+3

-----------------top/distinct-------------------------------
select top(5) * from StudentScore order by score asc
select top 3 * from StudentScore order by score desc
select top(3+2) * from StudentScore order by score desc
select top 10 * from StudentScore
select top 50 percent * from StudentScore order by score desc


select * from StudentScore
select distinct * from StudentScore
select distinct courseName from StudentScore

--------------------------聚合函數-------------------------
select * from StudentScore
select COUNT(*) from StudentScore
select MAX(score) from StudentScore
select MIN(score) from StudentScore
select AVG(score*1.0) from StudentScore
select SUM(score) from StudentScore
select
 分數最高的=MAX(score),
 分數最低的=MIN(score)
from StudentScore
--聚合函數對(NULL)值不做處理,當0來處理
--聚合函數經常與 select 語句的 group by 子句一起使用
--select 語句的選擇列表(子查詢或外部查詢)。
--compute 或 compute by 子句。
--having 子句。
-----------------------------var與count_big----------------------------
select * from StudentScore
select 成績 = VARp(autoId) from StudentScore
--返回給定表達式中所有值的填充的統計方差。是6.66666666666666
select 成績 = count_big(studentId) from StudentScore--都是返回9說明返回的是
--是所有項目數量的值count_big是bigint,count返回是int值

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章