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,统计语句,陆续整理添加吧的更多相关文章

  1. WordPress 常用数据库SQL查询语句大全

    在使用WordPress的过程中,我们少不了要对数据库进行修改操作,比如,更换域名.修改附件目录.批量修改文章内容等等.这个时候,使用SQL查询语句可以大大简化我们的工作量. 关于如何操作SQL查询语 ...

  2. 几个简单常用的Sql语句

    '; --查Cids为2的Gnumber列的和,列名为Ids select Cids,Plevel from People; select * from Salary; select * from S ...

  3. ***SQL统计语句总结(运用场景:运营分析,财务分析等)

    -- 统计三月的每天的数据量 ,) ,) ; --统计从5月19到6月29的数据量 , ) AS '日期', count(*) AS '医说数' FROM xm_feed a WHERE a.feed ...

  4. 常用的SQL数据库语句总结

    1as 的用处 as可以对表和列取别名 在开发过程中经常遇到开始给某一个的字段去field1的名称,但后来有感觉field1字段指定不确切,于是又把此字段改成了field2,由于开始认 为field1 ...

  5. COUNT分组条件去重的sql统计语句示例(mysql)

    常规情况下的sql分组统计为: ) from 表 where 条件 group by 字段; 但是有时往往需要添加不同的条件已经去重的统计以上语句就不能满足需求. 解决方案为: 1.添加条件的统计方案 ...

  6. 常用的sql数据库语句

    1.说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)法一:select * into b from a where 1 <>1法二:select top 0 * i ...

  7. 一些常用的SQL查询语句

    学习网站:http://www.w3cschool.cc/sql/sql-tutorial.html 一:查询所有表的属性 SELECT 'ALTER TABLE '+ CASE WHEN O.sch ...

  8. 渗透常用手工SQL注入语句合集

    1.判断有无注入点; and 1=1 and 1=2 2.猜表一般的表的名称无非是admin adminuser user pass password 等..and 0<>(select ...

  9. 1.sql统计语句

    select exam_item_code, exam_item, EXAMDATE, count(distinct patient_id) from (select t2.exam_item_cod ...

随机推荐

  1. A2DP协议笔记

    1.概述     A2DP(Advanced Audio Distribution Profile)是蓝牙的音频传输协议,典型应用为蓝牙耳机.A2DP协议的音频数据在ACL Link上传输,这与SCO ...

  2. Link Management Protocol (LMP)

    1.1. Link Management Protocol (LMP)   1.1.1.   Introduction and Theory The Link Manager (LM) transla ...

  3. GetLogicalProcessorInformation(XP3才支持)和GetLogicalProcessorInformationEx(WIN7才支持)

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms683194(v=vs.85).aspx 例子执行结果如下: https://ms ...

  4. Android Handler简单示例

    package com.firstapp.foo.firstapp; import android.os.Handler; import android.os.Message; import andr ...

  5. MVC 中的 ViewModel

    此文章总结自:http://rachelappel.com/use-viewmodels-to-manage-data-amp-organize-code-in-asp.net-mvc-applica ...

  6. magento 图片缓存是如何生成的

    Varien_Image_Adapter_Gd2 类 ,里面有个save()方法,通过图片格式拼出来的方法  call_user_func_array($this->_getCallback(' ...

  7. 【转】Http Cache最基本的一些东西

    Http Cache最基本的一些东西 Cache浏览器IEwebkitApache  Http的Cache机制总共有4个组成部分: Cache-Control: max-age=N(seconds)  ...

  8. HTML:Input元素标签的详细介绍

    总结Input的标签: Input表示Form表单中的一种输入对象,其又随Type类型的不同而分文本输入框,密码输入框,单选/复选框,提交/重置按钮等,下面一一介绍.1,type=text输入类型是t ...

  9. 微信小店 API 手册

    微信商铺API手册V1.13 目录 1.      商品管理接口.................................................................... ...

  10. javaScirpt学习之事件

    一.事件的添加和删除 不同浏览器,不同DOM级别,添加和删除事件的方法也不同,具体可以参见后面的EventUtil元素. 二.事件对象 在事件处理程序中,浏览器会为之传入一个event对象,该对象的常 ...