现有表t记录举例如下: select * from t; a b ----- a1 c a1 d b2 g b2 f b2 e ------ 共有5条记录 要求写出这样一个查询语句:查询表t的所有记录,查询结果中增加按照a分组后按照b排序的组内排序号。 查询结果举例如下: a b xh -------- a1 c 1 a1 d 2 b2 e 1 b2 f 2 b2 g 3 --------
select *from t
a b
-----
a1 c
a1 d
b2 g
b2 f
b2 e共有5条记录
要求写出这样一个查询语句:
查询表t的所有记录,查询结果中增加按照a分组后按照b排序的组内排序号。查询结果举例如下:
a b xh
---------
a1 c 1
a1 d 2
b2 e 1
b2 f 2
b2 g 3帮忙写一条SQL语句!
a varchar(5),
b varchar(5)
)insert into t (a,b)
select 'a1','c' union all
select 'a1','d' union all
select 'b2','g' union all
select 'b2','f' union all
select 'b2','e'
select a,b,(select count(*) from t as tb1 where tb1.a = t.a and tb1.b <=t.b) as cnt from t order by a,b--result
a1,c,1
a1,d,2
b2,e,1
b2,f,2
b2,g,3