位置: 编程技术 - 正文

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

  • 印花税减免税优惠政策202
  • 销项税大于进项税时怎么处理
  • 个人独资企业税种有哪些
  • 中国税务精神是谁提出的
  • 固定资产一次性扣除申报表怎么填
  • 扣非净利润为什么比净利润低
  • 小规模纳税人税率有几种
  • 不动产融资租赁税率是多少
  • 接受虚开增值税 经侦立案
  • 年末发票
  • 商业银行退出
  • 如何理解出口退税政策
  • 银行收到对方付款的会计分录
  • 打款金额少于开票金额
  • 开完发票业务没收入需要确认收入入账吗?
  • 机械设备增值税税率
  • 没有外管证就开具了发票
  • 个人劳务报酬个人所得税怎么算
  • 外地预缴个人所得税如何入账及申报
  • 金税盘开票出现离线发票金额超出限制怎么设置?
  • 销售退回冲减主营业务收入吗
  • 汽车展厅布置需要什么
  • 高新创投企业所得税税率
  • 补缴房产税需要什么资料
  • 怎样获取
  • 金税盘申请电子发票成功后怎样手工导入
  • 高新技术企业研发费占比
  • hif文件怎么打开
  • 多台电脑如何建立局域网
  • 企业所得税会计准则
  • 高新企业研发费用占比规定
  • 企业所得税的纳税人包括哪些
  • 固定资产增加应计入什么
  • mapbox wms
  • 委托证券公司购入公允价值为100万元的股票
  • php面向过程
  • 关于商业承兑汇票的多选题有哪些
  • ftp port命令
  • 总结php删除字符的方法
  • reorg table 命令
  • 什么是应收账款信用管理制度
  • python的series
  • 转让土地使用权会计分录
  • 营改增后房地产企业增值税如何核算
  • sql server应用
  • 运输公司开具的增值税专用发票谁抵扣
  • 新公司成立需要刻哪些章
  • 每月企业所得税怎么征收
  • sqlserver 查询语句
  • 公司缴纳残保金的标准
  • 房地产会计分录怎么做
  • 出口退税相关税法文件
  • 给保安买大衣算贿赂吗
  • 社会保险中断后还可以续保吗
  • 营改增会计分录怎么做
  • 母子公司间固定资产交换
  • 预付卡充值入什么科目
  • 固定资产改建支出的扣除规定
  • 应收股利在资产负债表中怎么填
  • 工会经费交纳
  • mysqlgroupby用法解析详细
  • windows8计算机在哪儿
  • xp系统字体安装方法
  • winxp 移动硬盘
  • dmidecode命令
  • windows xp桌面图标
  • win8自启动在哪儿设置
  • Win8开启SmartScreen筛选器保护上网安全
  • 九九乘法表vb
  • div+css布局是什么
  • html图像元素
  • python 初级
  • nodejs中的session
  • linux命令统计
  • shell脚本 -ne 0
  • JavaScript onkeydown事件入门实例(键盘某个按键被按下)
  • javascript教程
  • jquery iframe写入内容
  • 辽宁省视同缴费标准?
  • 计提消费税的会计分录讲解
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设