2010年8月9日 星期一

分組小計

IF Exists(Select * from Tempdb..sysobjects where id=object_id('tempdb..#tmp0'))
drop table #tmp0

select aid=identity(int,1,1), empno,deptno into #tmp0 from tableA where eduuid='00101' order by deptno,empno

select *,(select count(1)+1 from #tmp0 a
where a.aid<#tmp0.aid and a.deptno=#tmp0.deptno) from #tmp0

沒有留言:

張貼留言