select identity(int,1,1) id,* into # from 表select code,department,year,(select top 1 mb from # where code=tem.code and department=tem.department and year=tem.year order by id desc),sum(md) md,sum(mc) mc,(select top 1 me from # where code=tem.code and department=tem.department and year=tem.year order by id) from # tem group by code,department,yeardrop table #
解决方案 »
- 求助一条惊天地 泣鬼神 史无前例 后无来者 的 超级SQL!!!!!!
- 求一个能够单步调试存储过程的工具
- 有一列数据 1至100 中间可能不连接,如何找出不连续的数字出来?
- 请问如何用sql语句修改字段的长度!
- 排序问题
- 一句话查询
- 修改一个字段的长度 alter table tablename modify colname ... 再往后怎么写呀?
- 如何使用 select * from SalesTbl 中的最近被修改的前十筆記錄?或前五筆記錄?
- 请问如果一台机器上有多个SQL SERVER实例,如何连接到非默认的实例上?
- 数据库导入错误?
- 一个SqlServer的触发器的设计
- 在定义表结构时使用VARCHAR()和NVARCHAR()有什么区别?
,(select top 1 md from #t bb where aa.code=bb.code and aa.department=bb.department and aa.year=bb.year order by xh )
,(select top 1 me from #t bb where aa.code=bb.code and aa.department=bb.department and aa.year=bb.year order by xh desc)
from #t aa
group by code,department,year
select code,department,year,(select top 1 mb from #temp where code=tem.code and department=tem.department and year=tem.year order by id desc),sum(md) md,sum(mc) mc,(select top 1 me from #temp where code=tem.code and department=tem.department and year=tem.year order by id) from #temp tem group by code,department,year
drop table #temp