位置: 编程技术 - 正文

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

  • 所得税减免会计分录
  • 房屋租金可以开发票吗
  • 扫码开票开错了怎么改
  • 企业支付宝要交哪些税
  • 公帐一个月能提多少现金出来
  • 应收账款转入呆账如何做帐
  • 房产税应由哪方交纳
  • 企业开办时间是什么意思
  • 预付费卡税务处理
  • 支付职工医药费计入什么科目
  • 建筑企业临时工工资申报个税
  • 3项经费计提比例2015
  • 库存商品的成本核算
  • 发票已认证还能作废吗2020
  • 应交税费是什么科目借贷方向
  • 建筑企业增值税预缴
  • 电子银行承兑汇票有风险吗
  • 电梯的运行与维护
  • 维修服务费税率是多少?
  • 应计入增值税一般纳税人认定标准的“年应税销售额”
  • 收到社保补贴计入什么科目
  • 2019附加税优惠政策
  • 加工贸易企业如何财务管理账务流程
  • 进厂的政府补贴怎么拿
  • 9个点的税率有哪些
  • 网络适配器感叹号代码43
  • 如何清理插件残留
  • 市政府的财政拨款怎么算
  • 外购的福利费要转出吗
  • image driver
  • 无法偿还应付账款账务处理
  • 固定资产改造后如何计提折旧
  • 一般合同怎么写才有效
  • 建造合同完工百分比法
  • 武陵山脉海拔
  • 注销报税是什么意思
  • webpack常用属性
  • 房屋租赁费属于什么税收分类编码
  • 给员工期权和给股票的区别
  • 错误日志怎么修复
  • 冲销去年暂估成本对企业所得税的影响
  • mongodb的索引种类
  • mongodb简单使用
  • 销售成本是付现成本吗
  • 废品材料回收的会计分录
  • 公司开一般户和基本户开哪个好
  • 上市公司限制性股票个人所得税
  • 年度汇算清缴后补税,账务要调整吗
  • 营业外支出核算的内容
  • 广告牌制作计入什么科目
  • 对方企业倒闭了是否能函证
  • 应该是先付款还是先开发票
  • 代销手续费怎么做账
  • 国债利息收入企业所得税调增
  • 承兑汇票兑现账户是什么
  • 过程中必须有哪两种状态
  • 企业一般用什么系统
  • sql server连接方式
  • mysql替换命令
  • xp系统安装版如何安装
  • freebsd中文手册
  • 苹果电脑快捷键截图怎么截
  • 重装系统前 病毒怎么办
  • 如何禁止win10系统更新到win11
  • winxp破解登录密码
  • win8磁盘分区
  • mac sip怎么打开
  • linux dev/sr0
  • linux命令shell脚本
  • python之virtualenv的简单使用方法(必看篇)
  • android蓝牙连接过程
  • vue远程调用组件
  • pm2启动nodejs
  • jquery 图片裁剪
  • 使用GeoPainter一步一步布置场景
  • javascript教程
  • python中的变量
  • 深入浅出jquery
  • 委托代征管理办法最长有效期
  • 苏州社保一卡通要充值吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设