- 论坛徽章:
- 0
|
最初由 magicangel 发布
[B]select 1 id,\'a\' a,4 b
into #magic
union
select 2,\'a\',3
union
select 3,\'a\',2
union
select 4,\'b\',5
union
select 5,\'b\',1
union
select 6,\'c\',7
union
select 7,\'c\',6
union
select 8,\'c\',8
select identity(int) id,a,b into #tmp from #magic order by a,b
--------------------------------------------------------------------------------------
#tmp表里就是你要的结果。
--------------------------------------------------------------------------------------
还有一种是这样的需求:
select a.id,a.a,a.b ,count(1) seq
from #magic a,#magic b
where a.a=b.a and a.b>=b.b
group by a.id,a.a,a.b [/B]
发觉你的一个特点,喜欢用union!
不过你这个好像不能解决他的问题?
靠,错误的理解了你的意思了,
原来union是这个意思,放在查询分析
器中用了一下,原来如此!
呵呵,学了一小招!!!!! |
|