Microsoft SQL Server学习(五)--操作符聚合函数
- 算术运算符
- 逻辑运算符
- 比较运算符
- 聚合函数
算术运算符(+ - * / )
select score*2 as 成绩翻倍 from class_A
update class_A
set score=score+20
where score<70
update class_A
set score=score-20
where score>70
update class_A
set score=score/2
where score>70
逻辑运算符(and/or/between A and B )
select * from class_A
select * from class_A where score >=80 and sex = 'male'
select * from class_A where score >=80 or sex = 'male'
select * from class_A where score between 60 and 80
比较运算符(< > <= >= <> != = )
介词查询 in(a,b…):在a、b中查询
Select * from class_A
Where score in(60,80)
去除重复值 distinct
Select distinct 列名 from 表名
查询前N条数据 top
Select top 2 * from class_A
查询前百分比条数据 top percent
Select top 20 percent * from class_A
查询后N条数据
Select top 4 * from class_A
Where score not in
(select top 3 score from class_A)
模糊查询like
Select * from class_A where name like '%娜%'
Select * from class_A where name like '文_'
Select * from class_A where name like '[文][章]'
Select * from class_A where name like '[李%]'
Select * from class_A where name like '%娜%'
% 表示任意通配
_ 表示一个字符通配
[] 表示集合([a-z]、[123]、[中山]、[中][山])
[中山]等价于[中][山]
[]中文要使用%或_
排序order by(默认为升序)
升序
Select * from class_A
Order by score
降序
Select * from class_A
Order by score desc
分组group by
在分组时,查询字段必须与分组的字段一致或者查询条件使用的是聚合函数
聚合函数
(1)统计函数
1)Count():统计总数
2)Max():最大值
3)Min():最小值
4)Avg():平均值
5)Sum():总和
6)Var():方差
使用having进行分组筛选
Select 列名1,聚合函数 from 表名
Group by 列名1
Having 聚合函数条件
select sum(score) as 总分 from class_A
select count(name) as 总人数 from class_A
select max(score) as 最高分 from class_A
select min(score) as 最低分 from class_A
select avg(score) as 平均分 from class_A
select name,AVG(score) from class_A group by name,score
having score > 60
select name,avg(score) from class_A group by sex,name
having avg(score) <68 and sex='male'
select avg(score) as 平均分 from class_A where sex='male'
select avg(score) as 平均分 from class_A where sex='female'
Microsoft SQL Server学习(五)--操作符聚合函数的更多相关文章
- Microsoft SQL Server学习(七)--函数视图
系统函数 视图 索引 1.系统函数 (1) ()数学函数 Abs() 绝对值 Floor() 向下取整 Ceiling() 向上取整 Sin() 返回指定角度(以弧度为单位)的三角正弦值 Pi() 圆 ...
- SQL SERVER 2005允许自定义聚合函数-表中字符串分组连接
不多说了,说明后面是完整的代码,用来将字符串型的字段的各行的值拼成一个大字符串,也就是通常所说的Concat 例如有如下表dict ID NAME CATEGORY 1 RED COLOR ...
- SQL SERVER 2005允许自定义聚合函数
不多说了,说明后面是完整的代码,用来将字符串型的字段的各行的值拼成一个大字符串,也就是通常所说的Concat 例如有如下表dict ID NAME CATEGORY 1 RED COLOR ...
- Microsoft SQL Server学习(一)--基本概念
数据库的分类 关系型数据库 非关系型数据库 数据库的发展 数据都是以文件的形式存储在硬盘上FATFAT32NTFS LinuxEXT 数据库设计流程 文件系统缺陷 数据库的专业术语 数据库引擎服务 E ...
- Microsoft SQL Server学习(六)--查询语句
联合查询 use student --建表 create table class_A( id int primary key, name varchar(50), sex char(50), cour ...
- Microsoft SQL Server学习(四)--约束
SQLServer - 约束 主要是为了保证数据库中的数据一致性.有效性.准确性, 从而提高了数据库中数据的正确性 一.约束的分类 在SQLserver中,约束分三种不同类型 1.实体约束 实提约束是 ...
- SQL Server(五)——常用函数
1.数学函数:操作一个数据,返回一个结果 --取上限ceiling select code,name,ceiling(price) from car ; --取下限 floor select floo ...
- SQL Server(五)——常用函数 转
1.数学函数:操作一个数据,返回一个结果 --取上限ceiling select code,name,ceiling(price) from car ; --取下限 floor select floo ...
- Microsoft SQL Server学习(二)
目录 关于数据库的语法: 1.创建数据库 create database 数据库名 on primary (主文件属性(name,filename,size等)) -用逗号隔开次要主要文件和次要文件 ...
随机推荐
- uva 10765 Doves and Bombs(割顶)
题意:给定一个n个点的连通的无向图,一个点的"鸽子值"定义为将它从图中删去后连通块的个数.求每一个点的"鸽子值". 思路dfs检查每一个点是否为割顶,并标 ...
- POJ 2299 Ultra-QuickSort(线段树+离散化)
题目地址:POJ 2299 这题以前用归并排序做过.线段树加上离散化也能够做.一般线段树的话会超时. 这题的数字最大到10^10次方,显然太大,可是能够利用下标,下标总共仅仅有50w.能够从数字大的開 ...
- IOS-Storyboard控制器切换之TabBar(3)
TabBar与Push相反,他以底部为导航 以头部为内容区域,如图: 打开storyboard文件,创建一个UITabBarController文件到画板中,默认带了2个 UIViewControll ...
- 一起talk C栗子吧(第九十回:C语言实例--使用管道进行进程间通信三)
各位看官们,大家好,上一回中咱们说的是使用管道进行进程间通信的样例.这一回咱们说的样例是:使用管道进行进程间通信.只是使用管道的方式不同样.闲话休提,言归正转.让我们一起talk C栗子吧! 我们在前 ...
- Bootstrap button源码分析
/* ======================================================================== * Bootstrap: button.js v ...
- 同一个站点下,兼容不同版本的JQuery
https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page Y ...
- 8-13 canvas专题-阶段练习二(下)
8-13 canvas专题-阶段练习二(下) <!DOCTYPE html> <html lang="zh-cn"> <head> <me ...
- 洛谷P1600 天天爱跑步——树上差分
题目:https://www.luogu.org/problemnew/show/P1600 看博客:https://blog.csdn.net/clove_unique/article/detail ...
- centOS封装
前言 在实际工作中,CentOS的安装需要设置的语言.键盘模式.时区等信息都存在很大程度上的雷同型.并且,安装完成后的一些设置工作也都是一样的.这些工作都可以在安装操作系统的时候自动完成.最终做到,安 ...
- 4-2 买家类目-dao(下)
查询出来的对象ProductCategory就已经有updateTime和createTime了,然而你只是把对象的categoryType给修改了一下,修改之后就执行save方法保存了.所以它还是原 ...