简单常用的sql,统计语句,陆续整理添加吧
1. 分段统计分数
if object_id('[score]') is not null drop table [score]
go
create table [score]([学号] int,[课程编号] varchar(8),[成绩] int)
insert [score]
select 2006091001,'04010101',75 union all
select 2006091001,'04010102',84 union all
select 2006091001,'04010103',68 union all
select 2006091001,'04010104',68 union all
select 2006091002,'04010101',86 union all
select 2006091002,'04010102',90 union all
select 2006091002,'04010103',67 union all
select 2006091003,'04010101',74 union all
select 2006091003,'04010102',45 union all
select 2006091004,'04010101',72 union all
select 2006091005,'04010101',56
---查询---
select
课程编号,
[80分上]=sum(case when 成绩>=80 then 1 else 0 end),
[80分下]=sum(case when 成绩<80 then 1 else 0 end),
[合计]=count(1)
from
score
group by
课程编号
---结果---
课程编号 80分上 80分下 合计
-------- ----------- ----------- -----------
04010101 1 4 5
04010102 2 1 3
04010103 0 2 2
04010104 0 1 1
(所影响的行数为 4 行)
2. 查询,删除重复数据
查询:
select * from admin a , ( SELECT b.password,b.reallyname
FROM [db_Blog].[dbo].[Admin] b group by password,reallyname
having count(*)>1 ) b where a.password=b.password and a.reallyname=b.reallyname 删除:
delete from admin where id in ( select min(id) from admin group by userName,password having count(*)>1)
)
简单常用的sql,统计语句,陆续整理添加吧的更多相关文章
- WordPress 常用数据库SQL查询语句大全
在使用WordPress的过程中,我们少不了要对数据库进行修改操作,比如,更换域名.修改附件目录.批量修改文章内容等等.这个时候,使用SQL查询语句可以大大简化我们的工作量. 关于如何操作SQL查询语 ...
- 几个简单常用的Sql语句
'; --查Cids为2的Gnumber列的和,列名为Ids select Cids,Plevel from People; select * from Salary; select * from S ...
- ***SQL统计语句总结(运用场景:运营分析,财务分析等)
-- 统计三月的每天的数据量 ,) ,) ; --统计从5月19到6月29的数据量 , ) AS '日期', count(*) AS '医说数' FROM xm_feed a WHERE a.feed ...
- 常用的SQL数据库语句总结
1as 的用处 as可以对表和列取别名 在开发过程中经常遇到开始给某一个的字段去field1的名称,但后来有感觉field1字段指定不确切,于是又把此字段改成了field2,由于开始认 为field1 ...
- COUNT分组条件去重的sql统计语句示例(mysql)
常规情况下的sql分组统计为: ) from 表 where 条件 group by 字段; 但是有时往往需要添加不同的条件已经去重的统计以上语句就不能满足需求. 解决方案为: 1.添加条件的统计方案 ...
- 常用的sql数据库语句
1.说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)法一:select * into b from a where 1 <>1法二:select top 0 * i ...
- 一些常用的SQL查询语句
学习网站:http://www.w3cschool.cc/sql/sql-tutorial.html 一:查询所有表的属性 SELECT 'ALTER TABLE '+ CASE WHEN O.sch ...
- 渗透常用手工SQL注入语句合集
1.判断有无注入点; and 1=1 and 1=2 2.猜表一般的表的名称无非是admin adminuser user pass password 等..and 0<>(select ...
- 1.sql统计语句
select exam_item_code, exam_item, EXAMDATE, count(distinct patient_id) from (select t2.exam_item_cod ...
随机推荐
- 蓝牙BLE LINK LAYER剖析(二) -- PDU
DATA FORMAT The Link Layer has only one packet format used for both advertising channel packets and ...
- nodejs爬虫
前言 几个月之前,有同事找我要PHP CI框架写的OA系统.他跟我说,他需要学习PHP CI框架,我建议他学习大牛写的国产优秀框架QeePHP. 我上QeePHP官网,发现官方网站打不开了,GOOGL ...
- XCODE打包安装包步骤
1. 2. 3. 4. 5. 6. 7. 导出之后就可以看到一个后缀为.ipa 的安装包.
- 常用yum命令
yum list 查询所有可用软件包 yum search 关键字 查询和关键字相关的包 yum -y install 包名 加上-y自动回答yes yum -y update 包名 升级 yum ...
- android判断网络连接状态、联网类型、运营商
/** * 获取上网方式 * * @param mContext * @return */ public static String getNetType(Context mContext) { St ...
- about eclipse
导出javadoc command选择bin下的javadoc.exe 配置编码和文字 英文:-locale en_US -encoding UTF-8 -charset UTF-8 中文:-loca ...
- -tableView: cellForRowAtIndexPath:方法不执行问题
今天在学习UItableView 的时候,定义了一个属性 @property (weak, nonatomic) NSMutableArray *dataList: 在ViewDidLoad方法方法中 ...
- LightOj1285 - Drawing Simple Polygon(连接多边形各点)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1285 题意:给你一些点,然后把它们用一条线把它们连起来,构成一个多边形,不能有相交,必 ...
- linux i2c 设备节点读写
最近需要操作24C02,封装了一下函数方便以后操作. 参考链接: https://my.oschina.net/handawei/blog/68526 http://blog.csdn.net/one ...
- [BS-15] Values of type 'NSInteger' should not be used as format arguments
Values of type 'NSInteger' should not be used as format arguments 苹果app支持arm64以后会有一个问题:NSInteger变成64 ...