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', ...
随机推荐
- MySQL之高可用MHA部署
先说一下大概原理 虚拟机A ip为10.0.3.92 作为master 虚拟机B ip为10.0.3.102 作为slave1 虚拟机C ip为10.0.3.103 作为 ...
- s3c2140 开发板笔记
文章目录 原理图补充说明 开机串口输出 开发板硬件配置 参考文档 工具下载 代码下载 安装交叉编译器 编译kernel 制作文件系统 配置nfs 配置smb Minimal client-only S ...
- 实现一个函数,可以左旋字符串中的k个字符
ABCD左旋一个字符得到BCDAABCD左旋两个字符得到CDAB ABCD BACD BCAD BCDA CBDA CDBA CDAB 发现规律: 如果左旋一个字符则可以将第一个字符依次与后面的字符交 ...
- BinaryReader 自己写序列化
听说过BinaryReader和BinaryWriter吗? 序列化无非就是网络通信时所使用的传输数据的方式,而BinaryWriter可以将数据以二进制的方式写入到流当中.比如Int32型的1用Bi ...
- 推荐一个 基于 WebSocket 和 Redis 的 即时通信 开源项目
项目地址 : https://github.com/2881099/im 大家可以和 SignalR 比较看看 , 如何 ? ^^ ^^ ^^ 这是一个 网友 写的 , 他还写了 ...
- 我发起了一个 .Net 开源 数据库 项目 SqlNet
大家好 , 我发起了一个 .Net 开源 数据库 项目 SqlNet . 项目计划 是 用 C# 写一个 关系数据库 . 可以先参考我之前写的 2 篇文章 : 谈谈数据库原理 https://w ...
- ML(5)——神经网络1(神经元模型与激活函数)
上一章介绍了使用逻辑回归处理分类问题.尽管逻辑回归是个非常好用的模型,但是在处理非线性问题时仍然显得力不从心,下图就是一个例子: 线性模型已经无法很好地拟合上面的样本,所以选择了更复杂的模型,得到了复 ...
- JQury基础(一)样式篇
1 初识jQury 1.1 环境搭建 jQuery是一个JavaScript脚本库,不需要特别的安装,只需要我们在页面 标签内中,通过 script 标签引入 jQuery 库即可. <head ...
- C# 委托、lambda表达式和事件
什么是委托?委托就是持有一个或多个方法的对象,并且该对象可以执行,可以传递. using System; using System.Collections.Generic; using System. ...
- Java模板引擎之Freemarker
Freemarker定义: 一款模板引擎 Freemarker是一个web图层组件不是web框架,解析服务端数据到页面 小例子: <#list 集合 as item> list标签对集合进 ...