• 简单常用的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)
    ) 
  • 相关阅读:
    面向对象的程序设计-2-创建对象
    面向对象的程序设计-1-理解对象
    react组件的生命周期
    react-router 组件式配置与对象式配置小区别
    mobx @computed的解读
    十分钟介绍mobx与react
    less学习
    git-简单流程(学习笔记)
    几种视频编码器的编译及使用方法
    一位程序员工作10年总结的13个忠告
  • 原文地址:https://www.cnblogs.com/sishahu/p/3359754.html
Copyright © 2020-2023  润新知