select top 4 a,b,c,max(d) from TT group by a,b,c order by a asc,b asc, c desc 不过你这个提问还是有问题: 1.那个E如果以a,b,c分组是取不出来的,是否也需要提取最大的E? 2.另外你这个前四条是指满足a,b,c相同的前4条还是a,b,cGroup后 所有记录的前4条? 如是前者,一个SQL恐怕不行,如果是后者用我上面 这个语句吧.
select top 4 a,b,c,sum(d) from TT group by a,b,c order by a asc,b asc, c desc
用select top 4 a,b,c,sum(d) from TT group by a,b,c order by a asc,b asc, c desc不行,因为我要a,b,c,d,e这几个字段的值! bacaihong(煮酒论英雄:—) 你问的很对。1。也取E。E按表中对应的a,b,c,d相同的字段。 2。满足a,b,c相同的前4条。 就是在满足a,b,c条件的记录里按最大值找出前4条,
a,b,c是查询条件? 如果是的话 select top 4 a,b,c, max(d) as d,e,f,g as d from component where a='" & * & "' and b='" & * & "' and c='" & * & "' group by a,b,c,e,f,g order by a asc,b asc, c desc 你试试吧!!
上面错了个地方!修改下! a,b,c是查询条件? 如果是的话 select top 4 a,b,c, max(d) as d,e,f,g from component where a='" & * & "' and b='" & * & "' and c='" & * & "' group by a,b,c,e,f,g order by a asc,b asc, c desc 你试试吧!!
order by a asc,b asc, c desc
a,b,c,d,e,f,g 是表TT中的字段
想要得a,b,c,d,e,按a,b升序,c按降序,并且要求满足每一个a,b,c相同的记录里只取d值最大的前4条记录。
order by a asc,b asc, c desc
不过你这个提问还是有问题:
1.那个E如果以a,b,c分组是取不出来的,是否也需要提取最大的E?
2.另外你这个前四条是指满足a,b,c相同的前4条还是a,b,cGroup后
所有记录的前4条? 如是前者,一个SQL恐怕不行,如果是后者用我上面
这个语句吧.
order by a asc,b asc, c desc
order by a asc,b asc, c desc不行,因为我要a,b,c,d,e这几个字段的值!
bacaihong(煮酒论英雄:—)
你问的很对。1。也取E。E按表中对应的a,b,c,d相同的字段。
2。满足a,b,c相同的前4条。
就是在满足a,b,c条件的记录里按最大值找出前4条,
如果是的话
select top 4 a,b,c, max(d) as d,e,f,g as d from component where a='" & * & "' and b='" & * & "' and c='" & * & "' group by a,b,c,e,f,g order by a asc,b asc, c desc
你试试吧!!
a,b,c是查询条件?
如果是的话
select top 4 a,b,c, max(d) as d,e,f,g from component where a='" & * & "' and b='" & * & "' and c='" & * & "' group by a,b,c,e,f,g order by a asc,b asc, c desc
你试试吧!!