I
ifcansee
Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现的结果是取name=1的按照a字段排序的前5个
取name=2的按照a字段排序的前5个
取name=3的按照a字段排序的前5个
取name=4的按照a字段排序的前5个
取name=5的按照a字段排序的前5个
....
我用的sql语句是
select top 5 * from table1.dbf where name=1 order by a desc union
select top 5 * from table1.dbf where name=2 order by a desc union
select top 5 * from table1.dbf where name=3 order by a desc union
select top 5 * from table1.dbf where name=4 order by a desc union
select top 5 * from table1.dbf where name=5 order by a desc union
.....
不过不能执行,应该是union不能和order by同时用吧,可是我该怎么做实现这样的结果?
取name=2的按照a字段排序的前5个
取name=3的按照a字段排序的前5个
取name=4的按照a字段排序的前5个
取name=5的按照a字段排序的前5个
....
我用的sql语句是
select top 5 * from table1.dbf where name=1 order by a desc union
select top 5 * from table1.dbf where name=2 order by a desc union
select top 5 * from table1.dbf where name=3 order by a desc union
select top 5 * from table1.dbf where name=4 order by a desc union
select top 5 * from table1.dbf where name=5 order by a desc union
.....
不过不能执行,应该是union不能和order by同时用吧,可是我该怎么做实现这样的结果?