数据检索

-------------------------------数据检索-----------------------------------
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值

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