sqlserver 模糊查询,连表,聚合函数,分组
use StudentManageDB
go
select StudentName,StudentAddress from Students
where StudentAddress like '天津%' select StudentName,StudentAddress from Students
where StudentName like '%小%' select * from ScoreList
where CSharp between 80 and 90 select StudentName,StudentAddress,Birthday from Students
where Birthday between '1987-01-01' and '1988-01-01' select StudentName,StudentAddress,age from Students
where Age in(21,22,23) select StudentName,StudentAddress,age from Students
where StudentName in('王小虎','贺小张') select SUM(CSharp) as C#总成绩 from ScoreList select 总人数=COUNT(*) from Students select MAX(Csharp) as C#最高分 ,MIN(CSharp) as C#最低分,AVG(CSharp) as C#最低分 from ScoreList select Students.StudentId,C#成绩=CSharp,StudentName,ClassName
from ScoreList
inner join Students on Students.StudentId=ScoreList.StudentId
inner join StudentClass on Students.ClassId=StudentClass.ClassId
where CSharp >80 select Students.StudentId,StudentName,Gender ,C#成绩=CSharp from Students
left outer join ScoreList on Students.StudentId=ScoreList.StudentId
where Gender='男' select Students.StudentId,StudentName,Gender ,C#成绩=CSharp from ScoreList
left outer join Students on Students.StudentId=ScoreList.StudentId
where Gender='男' select 班级=StudentClass.ClassName,人数=COUNT(*),C#最高分=Max(CSharp),DB最高分=MAX(SQLServerDB),
AVG(CSharp) as C#平均分,AVG(SQLServerDB) as DB平均分
from Students
inner Join StudentClass on Students.ClassId =StudentClass.ClassId
inner join ScoreList on ScoreList.StudentId=Students.StudentId
group by ClassName
having AVG(CSharp)>=70 and AVG(SQLServerDB)>=70 select * from ScoreList
select StudentId from ScoreList group by StudentId having COUNT(*)>1 select * from ScoreList
where StudentId in(select StudentId from ScoreList group by StudentId having COUNT(*)>1)
order by StudentId select * from ScoreList
where (select COUNT(*) from ScoreList s where s.StudentId=ScoreList.StudentId)>1
order by StudentId
sqlserver 模糊查询,连表,聚合函数,分组的更多相关文章
- ef实现一次查询多个聚合函数的字段
想用ef来写一个统计字段的语句,如下所示 select sum(price) as price_total, sum(amount) as amount_total from table1 发现似乎实 ...
- 18 12 06 sql 的 基本语句 查询 条件查询 逻辑运算符 模糊查询 范围查询 排序 聚合函数 分组 分页 连接查询 自关联 子查询
-- 数据的准备 -- 创建一个数据库 create database python_test charset=utf8; -- 使用一个数据库 use python_test; -- 显示使用的当前 ...
- mysql 数据操作 单表查询 group by 聚合函数
强调: 如果我们用unique的字段作为分组的依据,则每一条记录自成一组,这种分组没有意义 多条记录之间的某个字段值相同,该字段通常用来作为分组的依据 如果按照每个字段都是唯一的进行分组,意味着按照这 ...
- mysql 数据操作 单表查询 group by 聚合函数 没有group by情况下
聚合函数只能用在组里使用 #没有group by 则默认算作一组 取出所有员工的最高工资 mysql> select max(salary) from employee; +---------- ...
- sqlserver模糊查询【转】
http://blog.csdn.net/liuxinxin1125/article/details/5444873 SELECT * FROM user WHERE name LIKE ';%三%' ...
- Django模型层之字段查询参数及聚合函数
该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. 字段查询是指如何指定SQL WHERE子句的 ...
- django字段查询参数及聚合函数
字段查询是指如何指定SQL WHERE子句的内容.它们用作QuerySet的filter(), exclude()和get()方法的关键字参数. 默认查找类型为exact. 下表列出了所有的字段查询参 ...
- MySQL☞聚合函数/分组函数
分组函数(聚合函数) 1.count(*/列名): a.*:求出该数据的总条数 select count(*) from 表名 b.列名:求出该列中列名不为null的总条数 select cou ...
- mysql关联模糊查询他表字段
如下:订单表关联了用户的id(多个),要根据用户名模糊查询订单信息,但是订单表只有id.创建视图用不着,咱也没权限.于是如下 SELECT * FROM ( SELECT cu.id AS 'id', ...
随机推荐
- day28Spark
PS:因为Spark是用内存运行 的,非常快 PS: 1.下面就是将conf的spark-env.template改变成spark-env.sh,并添加红色部分 2.修改slaves文件添加从设备 启 ...
- log4net 自定义日志级别记录多个日志
程序中原来只记录一个日志,现在我要写一个用户操作日志,需要与原来的日志分开,在config文件中一阵折腾无果(要么写不全,要么写重了,反正没办法完美分离,要么与现存代码没办法完美兼容),差点放弃准备自 ...
- MySQL Replication--修改主键为NULL导致的异常
测试环境:MySQL 5.5.14/MySQL 5.6.36 测试脚本: create table tb001(id int primary key,c1 int); alter table tb00 ...
- EXtJS Ext.data.Model
(一).首先我们介绍一下Model类中比较常用的几个属性,如果我们想构建一个Model类,最主要的属性就是(Fields)属性,这个属性接受一个数组.用来设置Model中所包含的字段.定义的格式如下: ...
- 不能将“this”指针从“const SqQueue<ElementType>”转换为“SqQueue<ElementType> &
错误 1 error C2662: “int SqQueue<ElementType>::getLength(void)”: 不能将“this”指针从“const SqQueue<E ...
- Go thrift使用举例
thrift 最初是 facebook 开发使用的 rpc 通信框架,后来贡献给了 apache 基金会,出来得比较早,几乎支持所有的后端语言,使用非常广泛,是不可不知的一个网络框架. 和 grpc ...
- 批处理手动设置电脑的ip
参考: http://blog.csdn.net/jiangzhanchang/article/details/7063152 http://wenda.haosou.com/q/1378697364 ...
- ML: 降维算法-LE
PCA的降维原则是最小化投影损失,或者是最大化保留投影后数据的方差.LDA降维需要知道降维前数据分别属于哪一类,而且还要知道数据完整的高维信息.拉普拉斯特征映射 (Laplacian Eigenmap ...
- 错误 Run-time error nnn at xxxx; 错误
出现runtime error临时解决办法,于注册表位置中找到如下键值HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Gdiplus,然后把键DisableTIFFCo ...
- ios导航栏和tabbar的坑
多年不写ios,目前重构项目,发现navBar和tabbar需要注意的点,记录备忘 translucent属性会导致view起始点的变化,默认为透明,和设计图有色差,改成不透明以后,坐标位置有变化,修 ...