34,588
社区成员
发帖
与我相关
我的任务
分享
select a.type,b.type ,count(*)
FROM a ,b
where b.r_id=a.r_id
GROUP BY a.type,b.type
select 序列 = (select count(1)+ 1 from ta where a.id > id)
,*
froom ta a
select 序列 = (select count(1)+ 1 from ta where a.id > id)
,*
froom ta a
--2000
--升序用<,降序用>
select px = (select count(1) from
(
select a.type,b.type ,count(*) cnt FROM a ,b where b.r_id=a.r_id GROUP BY a.type,b.type
) m where cnt < n.cnt) + 1,* from
(
select a.type,b.type ,count(*) cnt FROM a ,b where b.r_id=a.r_id GROUP BY a.type,b.type
) n
)
--直接顺序用px = identity(int,1,1)
select px=identity(int,1,1) ,a.type,b.type ,count(*) cnt into tmp FROM a ,b where b.r_id=a.r_id GROUP BY a.type,b.type
select * from tmp
--2005用row_number()
select a.type,b.type ,count(*) cnt , px = row_number() over(order by a.type , b.type) FROM a ,b where b.r_id=a.r_id GROUP BY a.type,b.type
declare @tb table (v varchar(80))
insert into @tb select 's'
insert into @tb select 'b'
insert into @tb select 'c'
insert into @tb select 'o'
select id=row_number() over (order by v),v from @tb