Code
 -- 年级排名和班级排名
declare @sql varchar(4000),@nclassid int,@nexamid int  select @sql='' select @nclassid=38 select @nexamid=19
select @sql=@sql+'max(case scoursename when '''+scoursename+''' then descore else 0 end) '+scoursename+','
from (select distinct scoursename from t_card_course where id in (select ncourseid from t_card_examcou where nclassid =+@nclassid and nexamid=+@nexamid )) a  
exec('
select nclassid, name  姓名,'+ @sql+ 'sum(descore) 总分
into #temp 
from ( 
 select b.nclassid,b.name,a.descore,c.scoursename from t_card_score a,t_stu b,t_card_course c,t_card_examcou d 
 where a.nstuid=b.id and a.ncouexamid in
 (select id from t_card_examcou where nclassid in (select id from t_card_class where ngradeid =(select ngradeid from t_card_class where id='+@nclassid+' and nschoolid=(select nschoolid from t_card_class where id='+@nclassid+')))  and nexamid='+@nexamid+' ) 
and a.ncouexamid=d.id and d.ncourseid=c.id group by b.nclassid,b.name,a.descore,c.scoursename )as a
 group by name,nclassid

select *,班级名次=(select count(总分) from #temp where 总分>y.总分 and nclassid=y.nclassid)+1 into #tempclass from #temp y   
select *,年级名次 =(select count(总分) from #tempclass where 总分>x.总分)+1 into #tempok from #tempclass x where nclassid ='+@nclassid+' order by 班级名次

alter table #tempok drop column nclassid
select * from #tempok
')

动态SQL应用(成绩排名)相关推荐

  1. 2021高考个人成绩排名查询,2021新高考八省联考实力排名:怎么查联考成绩在全省排名?...

    选择科目 测一测我能上哪些大学 选择科目 领取你的专属报告 > 选择省份 关闭 请选择科目 确定 v> 新高考八省联考已经接近尾声了,此次考试对八个省份的考生来说,是高考前的一场重大模拟考 ...

  2. PAT (Basic Level) Practice1004 成绩排名

    1004 成绩排名 一.题目 读入n(>0)n (>0)n(>0)名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 二.输入输出 输入格式 每个测试输入包含 1 ...

  3. mysql查询成绩并排名_Mysql 查询实现成绩排名

    近日系统要实现总分成绩排名,而且相同分数的学生排名要一样,在网上搜了一圈,没有找到合适的方法,只能靠自己实现了,这里提供两种方法 1.sql查询实现 测试如下: mysql> select * ...

  4. SQL查询成绩表中的每科第三名

    SQL查询成绩表中的每科第三名 题目要求 表格数据 grade表 c_id c_no c_name 1 1 80 1 2 90 1 3 70 1 4 95 2 1 64 2 2 88 2 3 89 2 ...

  5. c语言:成绩排名(结构体)

    题目详情 定义结构体struct stu,编写成绩排名函数:void sort(struct stu *ps,int n),对结构体数组按成绩排名. 程序功能为读入整数N(N<100),再读入N ...

  6. 2021河南省高考文科成绩排名查询,2021年河南高考成绩排名及一分一段表

    一分一段表是很重要的填报志愿的依据,也是各大高校划自己分数线的一部分依据.一分一段表是从高到低的排名,考生根据成绩对照一分一段表,就可以知道自己在全省的排名,再参照各类学校各批次招生计划数,确定自己该 ...

  7. Mybatis入门:3(动态sql)

    动态sql语句 if标签 基本使用 一.在ProductDao接口中创建一个查询方法findByType import com.domain.Product;import java.util.List ...

  8. MyBatis动态SQL之 set 和 trim标记的使用示例

    2019独角兽企业重金招聘Python工程师标准>>> 和之前的where一样,set和trim也是智能标记 在之前的user.xml中添加 <update id=" ...

  9. Oracle基础 动态SQL语句

    一.静态SQL和动态SQL的概念. 1.静态SQL 静态SQL是我们常用的使用SQL语句的方式,就是编写PL/SQL时,SQL语句已经编写好了.因为静态SQL是在编写程序时就确定了,我们只能使用SQL ...

  10. MyBatis动态SQL(认真看看, 以后写SQL就爽多了)

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 来源:cnblogs.com/homejim/p/9909657. ...

最新文章

  1. (1)学习数组,集合,IEnumerable接口,引申学习迭代器
  2. iOS病毒XcodeGhost批量检测工具,开源Github(检测ipa文件)
  3. 社区网站功能实现系列(三):社区页面无刷新回发的一种实现方式
  4. 怎样使用Spring Boot项目的单元测试?
  5. 理解ASP.NET Core中的中间件
  6. ie浏览器网页版进入_IE浏览器打开网页提示无法打开Internet站点的解决办法
  7. linux的进程/线程/协程系列3:查看linux内核源码——vim+ctags/find+grep
  8. 一周试用yii开发一个带各种该有功能的web程序(三)
  9. 简析Windows Linux的内核映射
  10. RFID EPC Class1 Gen2电子标签笔记
  11. 【实用技巧】文件MD5修改方法
  12. 泡妞高手的经典三十六计
  13. Ubuntu 安装微信客户端
  14. 初几学的计算机二进制,说说二进制与计算机的那些事儿
  15. oracle修改数据库用户名密码,怎样修改oracle数据库的用户名密码
  16. 如何起Linux服务器的21端口,linux下开启ftp的21号端口
  17. Windows Speech SDK5.1的安装和使用(xp/win7)
  18. 【CSS】元素的伪类
  19. 超级账本源码分析(一) - 超级账本学习计划
  20. 构造函数的特点和作用

热门文章

  1. A pure java code of unrar. Decryption is supported.
  2. netcore磊科小企路由器使用测试-nr235p--测试结果令人气愤!!!!
  3. 《LeetCode力扣练习》第13题 C语言版 (做出来就行,别问我效率。。。。)
  4. bootstrape实战案例_第二百五十二节,Bootstrap项目实战-首页
  5. 余切表示matlab,matlab中 正弦余弦正切余切的画法 以及For while的用法
  6. g++ 安装python_mac编译安装faiss
  7. vue ajax highcharts,在vue项目中引入highcharts图表的方法(详解)
  8. mysql 启动安全模式_“ Word上次启动时失败,以安全模式启动Word ....”解决办法...
  9. android 属性动画 弧形,CSS分层动画可以让元素沿弧形路径运动
  10. 添加右键菜单_笔记本没有灭屏键?巧在右键菜单添加“关闭显示器”选项