位置: 编程技术 - 正文

sqlserver 统计sql语句大全收藏

编辑:rootadmin
1.计算每个人的总成绩并排名 select name,sum(score) as allscore from stuscore group by name order by allscore 2.计算每个人的总成绩并排名 select distinct t1.name,t1.stuid,t2.allscore from stuscore t1,( select stuid,sum(score) as allscore from stuscore group by stuid)t2where t1.stuid=t2.stuidorder by t2.allscore desc 3. 计算每个人单科的最高成绩 select t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(select stuid,max(score) as maxscore from stuscore group by stuid) t2where t1.stuid=t2.stuid and t1.score=t2.maxscore 4.计算每个人的平均成绩 select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(score) as avgscore from stuscore group by stuid) t2where t1.stuid=t2.stuid 5.列出各门课程成绩最好的学生 select t1.stuid,t1.name,t1.subject,t2.maxscore from stuscore t1,(select subject,max(score) as maxscore from stuscore group by subject) t2where t1.subject=t2.subject and t1.score=t2.maxscore 6.列出各门课程成绩最好的两位学生 select distinct t1.* from stuscore t1 where t1.id in (select top 2 stuscore.id from stuscore where subject = t1.subject order by score desc) order by t1.subject 7.学号 姓名 语文 数学 英语 总分 平均分 select stuid as 学号,name as 姓名,sum(case when subject='语文' then score else 0 end) as 语文,sum(case when subject='数学' then score else 0 end) as 数学,sum(case when subject='英语' then score else 0 end) as 英语,sum(score) as 总分,(sum(score)/count(*)) as 平均分from stuscoregroup by stuid,name order by 总分desc 8.列出各门课程的平均成绩 select subject,avg(score) as avgscore from stuscoregroup by subject 9.列出数学成绩的排名 declare @tmp table(pm int,name varchar(),score int,stuid int)insert into @tmp select null,name,score,stuid from stuscore where subject='数学' order by score descdeclare @id intset @id=0;update @tmp set @id=@id+1,pm=@idselect * from @tmp select DENSE_RANK () OVER(order by score desc) as row,name,subject,score,stuid from stuscore where subject='数学'order by score desc . 列出数学成绩在2-3名的学生 select t3.* from(select top 2 t2.* from (select top 3 name,subject,score,stuid from stuscore where subject='数学'order by score desc) t2 order by t2.score) t3 order by t3.score desc . 求出李四的数学成绩的排名 declare @tmp table(pm int,name varchar(),score int,stuid int)insert into @tmp select null,name,score,stuid from stuscore where subject='数学' order by score descdeclare @id intset @id=0;update @tmp set @id=@id+1,pm=@idselect * from @tmp where name='李四' . 课程 不及格(-) 良(-) 优(-) select subject, (select count(*) from stuscore where score< and subject=t1.subject) as 不及格,(select count(*) from stuscore where score between and and subject=t1.subject) as 良,(select count(*) from stuscore where score > and subject=t1.subject) as 优from stuscore t1 group by subject . 数学:张三(分),李四(分),王五(分),赵六(分) declare @s varchar()set @s=''select @s =@s+','+name+'('+convert(varchar(),score)+'分)' from stuscore where subject='数学' set @s=stuff(@s,1,1,'')print '数学:'+@s

推荐整理分享sqlserver 统计sql语句大全收藏,希望有所帮助,仅作参考,欢迎阅读内容。

sqlserver 统计sql语句大全收藏

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

动态SQL语句使用心得 在我们的项目中经常需要用到分面功能,而我以前呢用的方法现在看起来都是那麽的笨拙,当时是这样做的,每当要进行数据分页时就专们针对那个表

将表数据生成Insert脚本 比较好用的生成插入语句的SQL脚本 setANSI_NULLSONsetQUOTED_IDENTIFIERONgo--=============================================--Author:华岭--Createdate:----Description:将表数据生成Insert脚本--Demo:execpCreateInsertScript'B

SQL创建的几种存储过程 创建存储过程表名和比较字段可以做参数的存储过程CreatePROCEDUREsp_getTeacherInfo@TblNamenvarchar(),--表名@CmpStrnvarchar(),--参与比较的值@TblAtrnvarchar()--参与

标签: sqlserver 统计sql语句大全收藏

本文链接地址:https://www.jiuchutong.com/biancheng/349523.html 转载请保留说明!

上一篇:SQL MSSQL 常用代码大全(sql server常用)

下一篇:动态SQL语句使用心得(动态sql语句怎么写)

  • 企业固定资产入账新标准
  • 一般纳税人开劳务发票几个点
  • 企业所得税成本没有发票怎么处理
  • 向境外个人支付咨询费如何算税
  • 出差补贴计入工资总额吗
  • 企业承担的法律责任有哪些保险
  • 不在境内劳务是否付企业所得税
  • 进项抵扣怎么操作
  • 贴现费用计算公式
  • 应付未付的款项如何税务处理
  • 工程款增值税专用发票如何开具
  • 非独立核算的分公司如何报税
  • 增值税专用发票验票
  • 小规模纳税人出售不动产征收率
  • 单位为员工缴纳社保分录
  • 资产负债表如何调平
  • 所得税季报营业收入本年累计
  • 母公司代付子公司费用的委托书
  • 收到支票怎么处理
  • 转回给挂靠单位的钱怎么做分录
  • 企业外购零部件可以入哪个会计科目核算?
  • 企业集团内部各所属单位之间
  • 债券借贷业务属于表外业务吗
  • 公司年度财务报告怎么写
  • 管理费用劳务费包括什么
  • mac如何修改图片像素大小
  • 季度所得税计算方法
  • 全年一次性奖金税收计算器
  • php文件锁并发 性能
  • win10怎么设置硬盘为第一启动项
  • 前端lru
  • 黑尾鮰鱼
  • vue调用后端接口的方法
  • 库存现金总分类账怎么登记
  • 供热企业享受增值税吗
  • vue 百度地图 移动端
  • 在php中如何对多条记录进行分页
  • vue3.0创建
  • 退税发票在总局怎么开
  • 开发票的零税率和免税有什么区别
  • javascript教程
  • 消费积分如何做账
  • 企业所得税是怎么产生的
  • 什么是应收账款信用管理制度
  • mysqldump导入数据库
  • mongodb4
  • 增值税普通发票和专用发票有什么区别
  • 扣除未结话费是什么意思
  • 借管理费用贷应交税费个人所得税
  • 个人代人开普票个税怎么算
  • 已抵扣未申报的税额如何转出
  • 长期股权投资转让会计处理
  • 存货质押融资的公司有哪些
  • 宣传费税前扣除什么意思
  • 国外扣款手续费
  • 代理记账服务业务内容
  • 企业之间的往来款要1900万要交多少税
  • 支付的员工餐费怎么记账
  • 银行日记账更正
  • 签合同的名称和内容
  • 资产减值损失会计处理
  • 看过有趣的童话书,简单介绍下
  • mssql in
  • windows禁用usb口
  • 苹果mac双系统好不好
  • centos7光盘挂载方法
  • 做ghost备份
  • MAC OS X Yosemite开启深色模式的方法
  • mac隐藏菜单栏
  • 苹果手机
  • es6 new set()
  • node的使用场景
  • javascript基础书
  • 使用SQLite本地数据库
  • python怎么在网上赚钱
  • js写一个类
  • 广东共青团如何解绑微信
  • 福建省地方税务局领导名单
  • 公司购买车辆是什么费用
  • 为什么要进行进气歧管真空度检测
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设