数据检索

本文深入探讨了SQL查询的基本语法,包括数据检索、列名调整、聚合函数使用及复杂查询技巧,涵盖从基础到进阶的应用实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值