位置: 编程技术 - 正文

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

  • 网上代增值税开错不退
  • 增值税税额怎么算出来
  • 怎样注册投资有限公司
  • 金融企业哪些方面可以进行数据分析
  • 销售佣金计入什么会计科目
  • 合伙企业法人股东
  • 企业当年发放以往年度工资
  • 医疗单位门诊收费票据是发票吗
  • 国家研发补贴政策
  • 定期定额户个人所得税怎么申报
  • 购进国产设备的增值税处理规定
  • 电子承兑没到期如何贴现
  • 摊销保险费会计分录怎么写
  • 余利宝怎样
  • 通用机打发票可以抵扣税吗
  • 软件生产企业
  • 营改增后建筑公司自建行为所得税
  • 销售型公司进销项时会计分怎么写?
  • 公司为什么要成立工会委员会
  • 转回给挂靠单位的钱怎么做分录
  • 收到赞助费开什么发票
  • 建筑行业营改增税率变化
  • 公司购买五金用交税吗
  • 无形资产的相关税费包括增值税吗
  • 先扣社保再发工资可以吗
  • 收入确认的五个步骤
  • 个人所得税申报流程图
  • 房产税城镇土地使用税申报期限
  • CodeIgniter扩展核心类实例详解
  • 威尼斯海滩滑板场
  • 处置子公司的方式
  • 申报个人所得税是按应发工资还是实发工资
  • php获取当前时间提交数据库
  • php preg_quote
  • 刷题有什么作用
  • css过渡动画属性
  • 毕业设计教程
  • 广告费和业务招待费扣除标准中的全年销售收入是指
  • 税务局清税
  • 深究Python中的asyncio库-线程并发函数
  • 固定资产记到什么账本
  • 仓库折旧会计分录
  • 测验3: 基本数据类型 (第3周)
  • 文化事业建设费税收优惠2023
  • 未开票收入是怎么算的
  • 外经证办好了后怎么开票
  • 一般纳税人税务的比例
  • 计提城建税的会计分录怎么写
  • 公司名下的车怎样领免检标志
  • 先前收取的包装费用
  • 进口货物应纳增值税的计算公式
  • 外地施工企业异地施工
  • 外汇收入需要缴纳增值税吗
  • 月末如何计提增值税附加及增值税
  • 苗木税票怎么抵扣
  • 养老保险产生的利息怎么来的
  • 固定资产中如何计算折旧
  • 什么是库存现金限额
  • 审计测试会计分录怎么做
  • 企业支付的技术转让费计入管理费用吗
  • sqlserver2012安装失败原因
  • xp系统怎么取消自动关机
  • 一键ghost的功能
  • win10edge浏览器如何切换到ie
  • 免费升win10时升级后一直有效吗
  • linux 请求
  • cocos2dx ccbreader内存泄露
  • android源码分析实录
  • 酷狗模拟器
  • js事件怎么写
  • shell监控端口状态
  • jquery怎么打开
  • Python中强大的命令行库click入门教程
  • jquery悬浮显示
  • 佛山国家税务局招聘
  • 云南省税务局咨询电话
  • 高速公路通行费的税率
  • 国家税务定额发票票样
  • 国家税务总局遴选拟录取名单
  • 商铺转让费怎么开票项目
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设