SQL——实例

--SQL查询的完整语法

select top | distinct

字段

,表达式

,函数

,标量子查询

,...

from

数据源

where——筛选

条件(一般逻辑、范围、模糊、空值)

扫描二维码关注公众号,回复: 2165717 查看本文章

group by——分组聚合

字段

having——再次筛选

条件

order by

排序字段

select distinct
	ROW_NUMBER() over(order by stuName) as 序号,
	*,
	avg(stuScore) over() as 平均数,
	avg(stuScore) over(partition by stuOtherName) as 分组平均数
from
(
	values
	(1,'张三',100,'组长'),
	(2,'李四',88,'组长'),
	(3,'王五',99,'学委'),
	(4,'董二',77,'学委')
)
as tbl(stuId,stuName,stuScore,stuOtherName)

 


猜你喜欢

转载自blog.csdn.net/sndongcheng/article/details/74332106
今日推荐