位置: 编程技术 - 正文

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

  • 转登记纳税人按规定再次登记为一般纳税人后
  • 免税收入怎么做账务处理
  • 餐饮娱乐服务费进项税不能从销项税额抵扣
  • 金蝶利润表为什么没有收入
  • 质量体系证费用计入什么科目
  • 向境外支付赔偿金需要发票么
  • 公司基本户可以转私人账户吗
  • 营改增后销售不动产的收入
  • 小规模企业有了增值税吗
  • 药店商品进销差价
  • 钉钉报销费用明细怎么写
  • 股权转让资本公积怎么处理
  • 机械租赁费发票图片
  • 小规模增值税缴纳怎么算
  • 利润表净利润等于科目余额表
  • 消耗性生物资产与生产性生物资产的区别
  • 临时设施需要验收吗
  • 税务机构
  • 赠送礼品的具体做法有许多技巧和讲究大致涉及
  • 企业一次性支付多年费用 不摊销
  • 加装固态后如何分盘
  • win10文件用什么打开
  • 在win7中怎么安转只兼容win10的软件
  • 车辆哪些费用计税
  • 车辆的代驾费应该怎么收
  • 病毒变种太多
  • win10专业版如何改为家庭版
  • kb4577266补丁
  • php中字符串函数
  • 前端打包发布
  • 基于thinkphp的学园招聘系统项目源代码
  • php解析url参数
  • 买支票需要带什么章
  • 本部借给分公司的钱用交印花税吗
  • uniapp动态设置标题
  • 流动资产占总资产比重多少较为合适
  • php二维数组foreach
  • 心形岛屿叫什么名字
  • program status
  • es工具类
  • 模型参数是什么意思
  • aes加解密工具
  • 筹建期间发生的开办费用
  • 货物入库会计分录怎么做
  • php判断是否存在某字符串
  • 员工实际工资
  • 固定资产每月计提还是每年计提
  • 差旅费报销时如何处理
  • 个人所得税由单位还是个人缴纳
  • 营业外收入如何纳税
  • 消费税如何计量
  • 重分类调整的内容包括什么
  • 我国现行资源税主要采用什么税率
  • 企业银行存款属于什么会计要素
  • 付国外客户佣金怎么代扣代缴增值税
  • 月末应付职工薪酬为负数怎么办
  • 研发使用的设备有哪些
  • 长期股权投资减值准备借贷方向增减
  • 银行承兑汇票进行贴现的会计分录
  • 租房子租一半不租了违约金付的,房东不肯退钱怎么办
  • 应付账款在贷方负数
  • 财务负责人和办税员可以是一个吗
  • 计提工资时一定要发票吗
  • 修缮服务指什么
  • 电费发票未到怎么入账
  • 存货与总账对账
  • 新手学会计怎么学
  • 使用SSIS创建同步数据库数据任务的方法
  • mysql根据另一张表更新
  • win7系统打开浏览器后突然卡住了
  • linux命令行怎么用
  • 嵌入式linux开发用什么语言
  • 安卓listview用法
  • 充分发挥党员的先锋模范作用,积极
  • vue alain
  • 安卓hid通信
  • numpy基础知识
  • 地税网上办税服务厅
  • 企业所得税纳税申报表A类
  • 税务局风险防控工作总结
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设