数据如下
GroupID AddDate GroupTypeID
----------- ----------------------- -----------
115 2010-10-10 12:48:45.000 1
118 2010-04-21 15:08:24.000 1
126 2010-09-21 08:09:22.000 1
127 2010-10-11 14:09:59.000 1
124 2010-11-23 18:46:53.000 3
121 2010-05-27 08:26:30.000 1
133 2010-12-24 19:42:10.000 4
119 2010-09-21 19:06:08.000 3
116 2010-12-29 17:17:59.000 4
128 2010-10-06 21:44:33.000 2
125 2010-10-10 11:28:51.000 1
122 2010-09-16 21:45:18.000 1
123 2010-10-10 11:28:38.000 1
120 2010-06-30 06:47:52.000 1
117 2010-03-26 18:31:30.000 5
先简单解释一下:GroupTypeID一共有五种类型
现在我要在每种类型中取出按照时间倒叙的前两条数据
GroupID AddDate GroupTypeID
----------- ----------------------- -----------
115 2010-10-10 12:48:45.000 1
118 2010-04-21 15:08:24.000 1
126 2010-09-21 08:09:22.000 1
127 2010-10-11 14:09:59.000 1
124 2010-11-23 18:46:53.000 3
121 2010-05-27 08:26:30.000 1
133 2010-12-24 19:42:10.000 4
119 2010-09-21 19:06:08.000 3
116 2010-12-29 17:17:59.000 4
128 2010-10-06 21:44:33.000 2
125 2010-10-10 11:28:51.000 1
122 2010-09-16 21:45:18.000 1
123 2010-10-10 11:28:38.000 1
120 2010-06-30 06:47:52.000 1
117 2010-03-26 18:31:30.000 5
先简单解释一下:GroupTypeID一共有五种类型
现在我要在每种类型中取出按照时间倒叙的前两条数据
union
select top 2 * from tb where grouptypeid=2 order by adddate desc
union
select top 2 * from tb where grouptypeid=3 order by adddate desc
union
select top 2 * from tb where grouptypeid=4 order by adddate desc
union
select top 2 * from tb where grouptypeid=5 order by adddate desc
desc
不太记得了 试试这个
试试,感觉不太好
这个试试,在sql2005中可以用,2000的版本换个方法 了。