在查询语句中增加序号字段(sql server)
来源:互联网 发布:青少年编程软件 编辑:程序博客网 时间:2024/04/25 17:12
直接贴个例子
use student
/*
drop table #registerdetaillearning
drop table #v_usertotalcredit
drop table #achievementsys
drop table #xuankecredit
drop table #table
*/
--建立临时表
select * into #registerdetaillearning from registerdetaillearning a
where isnull(a.xj_level,a.stu_level)='200609'
select * into #v_usertotalcredit from v_usertotalcredit
select userid into #achievementsys from achievementsys where left(examid,6)=200707
select a.userid as userid,sum(isnull(b.studycredit,0)) as xuankecredit into #xuankecredit
from v_xuankehistory a left join subjectcoursesys b on a.courseid=b.courseid group by a.userid
--执行查询
select identity(int,1,1) as 序号, a.fdzname as 服务站,a.studentname as 姓名,a.userid as 用户名,a.studykind as 层次,
a.subject as 专业,a.telephone as 电话,a.phonenum as 手机,e.xuankecredit as 选课学分,
isnull(b.totalcredit,0) as 已取得学分
into #table
from #registerdetaillearning a left join #v_usertotalcredit b on a.userid=b.userid
left join #xuankecredit e on a.userid=e.userid
where b.totalcredit between 1 and 10 and a.userid not in (select userid from #achievementsys)
order by 服务站
select * from #table
use student
/*
drop table #registerdetaillearning
drop table #v_usertotalcredit
drop table #achievementsys
drop table #xuankecredit
drop table #table
*/
--建立临时表
select * into #registerdetaillearning from registerdetaillearning a
where isnull(a.xj_level,a.stu_level)='200609'
select * into #v_usertotalcredit from v_usertotalcredit
select userid into #achievementsys from achievementsys where left(examid,6)=200707
select a.userid as userid,sum(isnull(b.studycredit,0)) as xuankecredit into #xuankecredit
from v_xuankehistory a left join subjectcoursesys b on a.courseid=b.courseid group by a.userid
--执行查询
select identity(int,1,1) as 序号, a.fdzname as 服务站,a.studentname as 姓名,a.userid as 用户名,a.studykind as 层次,
a.subject as 专业,a.telephone as 电话,a.phonenum as 手机,e.xuankecredit as 选课学分,
isnull(b.totalcredit,0) as 已取得学分
into #table
from #registerdetaillearning a left join #v_usertotalcredit b on a.userid=b.userid
left join #xuankecredit e on a.userid=e.userid
where b.totalcredit between 1 and 10 and a.userid not in (select userid from #achievementsys)
order by 服务站
select * from #table
- 在查询语句中增加序号字段(sql server)
- sql查询中,增加序号
- SQL语句查询结果额外添加一列序号自动增加
- SQL语句查询结果额外添加一列序号自动增加
- SQL语句查询结果额外添加一列序号自动增加
- SQL 在查询结果中增加标记字段
- SQL SERVER在历史月表上增加字段,用到了SQL的游标和动态语句
- SQL Server中SQL语句插入序号的问题
- sql 语句增加字段
- 在SQL Server中通过SQL语句实现分页查询
- 在SQL Server中通过SQL语句实现分页查询
- 在SQL Server中通过SQL语句实现分页查询
- 在SQL Server中通过SQL语句实现分页查询
- 在SQL Server中通过SQL语句实现分页查询
- mysql在查询结果中自动添加序号字段列
- SQL Server 2008 中SQL查询语句中字段值不区分大小写问题处理
- SQL Server中查询所有数据库、所有表、字段的Sql语句
- sql语句在sqlserver中根据字段名查询,看哪些表包含了这个字段
- 内存管理内幕--动态分配的选择、折衷和实现(四)
- [精彩] 如何讲好售前PPT
- STL的简单应用
- 22年人生风雨路
- 使用jBPM开发企业流程应用之安装流程设计器
- 在查询语句中增加序号字段(sql server)
- scanf与回车的冲突
- 十招教你养成使用电脑好习惯
- c++ template
- 售前应该注意的几点
- Excel 2003函数应用完全手册
- 使用asp后产生的Server Application Error 解决方案
- 在PB中控制一条记录是否可以被修改
- Supporting RDMA on Linux