位置: 编程技术 - 正文

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语句怎么写)

  • 个人房产投资入股公司过户
  • 个体户超过定额怎么纳税申报
  • 网银转账往来款
  • 政府回购土地免税政策
  • 临时设施摊销方案怎么写
  • 资产负债表其他应付款计算公式
  • 权益筹资额计算公式
  • 本月实现利润总额的25%计算并结转应交所得税
  • 取得划拨或赠与资产需要缴企业所得税吗?
  • 新个税年终奖怎么申报
  • 怎么把原材料转为成本
  • 2018年城镇医保
  • 管理会计的目标包括多选题
  • 安装工程劳务合同
  • 外地预缴个人所得税会计分录
  • 开专票一定要公章吗
  • 涂料发票几个点的税
  • 计提了坏账准备对利润的影响
  • 成本法核算长期股权投资初始投资成本
  • 月末税金及附加税金的账务处理
  • 核销单怎么做
  • 进项发票抵扣范围
  • 发票有几个
  • window最新漏洞
  • 单位个税申报后可以撤销吗
  • 金税四期查到了怎么办
  • 高新技术企业所得税优惠政策最新2022
  • opencart 二次开发
  • macbookpro安装dmg
  • newacs.exe是什么进程
  • u盘格式化技巧
  • 用php做计算
  • php初学
  • 商品房契税申报是增量房申报吗
  • 福利企业的税收怎么算
  • 天堂之路歌曲
  • yii2框架中文手册
  • ci框架如何做api
  • 中科院t1
  • Win11 Build 25336 预览版发布:Snap 窗口新增最近 20 个标签选项
  • php怎么上传图片并保存到数据库
  • dos命令暂停停10s
  • firewall enable
  • 金融商品转让的销售额
  • python偏函数理解
  • 合同价格约定不明法律规定
  • 免征的教育费附加怎么做账
  • 免抵退申报汇总表在哪里
  • 为博客园开发了什么项目
  • 在建工程转入固定资产后又发生了后期支出会计处理
  • 企业筹建期间
  • 处置固定资产增值税收入与企业所得税收入不一致
  • 去年少计提费用
  • 行政单位应缴财政税金
  • 会计中制造费用包括哪些内容
  • 酒店的布草怎么铺
  • 进口增值税已抵进项税额
  • 提取安全生产费用是什么意思
  • 国有资产无偿划转税收政策
  • 房屋装修费用的会计科目
  • 微软系统无法开机怎么办
  • msi安装错误代码2503
  • win7磁盘c满了怎么办却又分不清哪些是该删除
  • win8系统怎么设置密码登陆
  • mac怎么把两个盘弄成一个盘
  • centos直接安装
  • windows7hosts文件
  • 高通umb
  • 基于jquery的表单验证插件
  • node.js中的http.request.end方法使用说明
  • python 爬取
  • stick function
  • javascript编写程序
  • 小规模纳税人进口环节的增值税税率
  • 美国买房hoa
  • 开票风险预警机制蓝色预警怎么办
  • 湖北省人民代表大会常务委员会关于深入开展
  • 实名办税的法律依据
  • 契税纳税申报表在哪里拿
  • 企业2017年
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设