表名:test1name fl money
1111 99 1
1111 99 2
1111 96 1
1111 96 1
2222 99 2
2222 98 1得到的结果是name fl money
1111 96 2
2222 98 1
条件是:
1、fl要最小的,每个相同名称只要一条。
2、money累加希望得到大家的帮助写出查询语句。在此感谢。
1111 99 1
1111 99 2
1111 96 1
1111 96 1
2222 99 2
2222 98 1得到的结果是name fl money
1111 96 2
2222 98 1
条件是:
1、fl要最小的,每个相同名称只要一条。
2、money累加希望得到大家的帮助写出查询语句。在此感谢。
select name,fl,sum(money) from test1 where (name,fl) in (select name,min(fl) from test1 GROUP BY name) GROUP BY name;
from (
select name,min(f1) as minF
from test1 A
group by name
)T1,test1 T2
where T1.name = T2.name and T1.minF=T2.f1
group by T2.name,T2.f1
select t1.name,t1.f1,sum(t1.money) from (select * from test1 order by f1) as t1 grou by t1.name
select t1.name,t1.f1,sum(t1.money) from (select * from test1 order by f1) as t1 group by t1.name
应该这样:select a.name,a.f1,sum(money) from t1 a, (select name, min(f1) f1 from t1 group by name) b
where a.name = b.name and a.f1 = b.f1 group by a.name;
select t1.name,min(f1),t1.money from (select name,f1,sum(money) money from t1 group by name,f1) as t1 group by t1.name
where not exists(select 1 from tt where a.name=name and a.money>money)
1111 96 2
where not exists(select 1 from tt where a.name=name and a.money>money) AND A.NAME='1111'
[征集]分组取最大N条记录方法征集,及散分....