题目如下:
create table t1 ( a char(10),b char(10)
)insert into t1
select '2006-4','100'
union all
select '2006-4','101'
union all select '2006-4','102'
union all select '2006-4','103'
union all select '2006-5','105'
union all select'2006-5','106'
要求出来的结果是:要求以下:a中的头两条记录2006-4 100
2006-4 101
2006-5 105
2006-5 106给出的答案是
select a.* from t1 a where a.b in(select top 2 b from t1 where a=a.a order by b)我想不明白的是
select top 2 b from t1 where a=t1.a order by b的结果才是
100
101
为什么总的SQL里面能出来
下面数据
2006-5 105
2006-5 106
create table t1 ( a char(10),b char(10)
)insert into t1
select '2006-4','100'
union all
select '2006-4','101'
union all select '2006-4','102'
union all select '2006-4','103'
union all select '2006-5','105'
union all select'2006-5','106'
要求出来的结果是:要求以下:a中的头两条记录2006-4 100
2006-4 101
2006-5 105
2006-5 106给出的答案是
select a.* from t1 a where a.b in(select top 2 b from t1 where a=a.a order by b)我想不明白的是
select top 2 b from t1 where a=t1.a order by b的结果才是
100
101
为什么总的SQL里面能出来
下面数据
2006-5 105
2006-5 106
select top 2 * from t1
select top 2 * from t1 order by b (desc)