select * from GCXWHZ a where ZRRID in(select top 2 ZRRID from GCXWHZ where GCXWID=a.GCXWID)
解决方案 »
- 请教,关于sql语句执行错误的问题?
- 查找不同课程但成绩相同的学生的学号、课程号和成绩。
- 这样的SQL语句Like条件怎么写??
- dm_exec_sql_text在哪里可以查询到?如何移除用户user1对其的所以操作权限?
- 关于数据文件导入数据库问题,高手指点!
- 如何判断当前是否已经安装了MSDE(SQL SERVER)以及其版本?
- 江湖救急!表中字段内容批量替换
- 关于bcp导出问题。。。
- sql server2000中怎样取得当前操作的sql语句,他保存在什么表/地方?
- 数据库复制问题
- 怎么取出一个字段的前4个字符?
- 为什么在查询分析器中print后面的东西(print (cast(@a5 as char(100))))不显示?
order by ZRRID
order by ZRRID
我是说每种GCXWID都取两条.也只取两条
也就是说GCXWHZ可能有1000条,是15种GCXWID的,每种都超过两条以上数据,那么我应该取得是30条数据
insert @t
select 1,1 union all
select 1,2 union all
select 1,3 union all
select 1,4 union all
select 2,2 union all
select 2,3 union all
select 2,4 union all
select 2,5 union all
select 3,1 union all
select 3,2 union all
select 3,3 union all
select 3,4 select * from @t a
WHERE ZRRID in(select TOP 2 ZRRID FROM @t WHERE GCXWID=a.GCXWID order by ZRRID )/*
GCXWID ZRRID
1 1
1 2
2 2
2 3
3 1
3 2
*/
select '1','1' union all
select '1','2' union all
select '1','3' union all
select '1','4' union all
select '2','7' union all
select '2','8' union all
select '2','9'
SELECT
*
FROM
@GCXWHZ a
WHERE
ZRRID
in
(SELECT Top 2 ZRRID from @GCXWHZ b where b.GCXWID = a.GCXWID)
---------------------------------
1 1
1 2
2 7
2 8