位置: 编程技术 - 正文

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
  • 企业外币交易会计核算方法
  • 烟草企业发生的广告和宣传费在当年营业收入15
  • 资源税如何进行账务处理
  • 社会保险差额征税的账务处理?
  • 如何判断发票是否重复
  • win10专业版技巧
  • php如何定义一个常量?常量名有哪些命名规则?
  • php框架基础教程
  • php删除数据库数据代码
  • Linux下 php5 MySQL5 Apache2 phpMyAdmin ZendOptimizer安装与配置[图文]
  • 公司之间债务转让合法吗
  • 503错误的原因和解决方法
  • 厂家赠送的商品如何走账
  • 小规模纳税人结转免交增值税
  • 高新技术企业取消资格怎么处罚
  • conime进程太多
  • 前端 php
  • 房屋租赁发票怎么入账
  • 热闻丨ChatGPT会替代你我吗?让它写了封情书后,我得到答案
  • move命令移动文件夹下所有文件
  • 文化事业建设费计入什么科目
  • 库存周转率会大于1吗
  • 防伪税控技术服务费订单号怎么查
  • 营销策划费会计分录
  • 发票校验码是什么在哪
  • 应付职工薪酬相关认定有哪些
  • 兼职人员的工资怎么做账
  • 验证码php代码
  • 织梦使用教程
  • 出口产品报关多少天
  • sql 字符串
  • 投资性房地产累计摊销
  • 车辆处置缴纳增值税税率
  • 企业外购的软件叫什么
  • 空调购买攻略
  • 公司购买银行理财产品收益交什么税
  • 资本公积的核算维度是什么
  • 各类奖金正确的排序
  • sql语句汇总数据
  • sql高级语句实例
  • sqlserver数据库怎么导出
  • sql server查询
  • bios1962错误
  • 解析包错误怎么解除
  • 开启windows远程桌面服务
  • win7安装sqlserver2000没反应
  • 还原windows是什么意思
  • fedora系统怎么安装
  • win7如何设置多用户
  • linux用户登录
  • u3d手游开发
  • unity公路制作
  • javascript以及javascript的作用
  • ug输入代码
  • 通过制作日晷我们可以探索发现一天之中
  • 安卓底层重写
  • jQuery Tags Input Plugin(添加/删除标签插件)详解
  • 开票地税怎么算的
  • 沈阳市税务局全称
  • 2021西安雁塔区第一幼儿园运动会
  • 累计预扣预缴税额
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设