假设是要按照表t中的字段a进行分组,取分组中b字段的最大值,那查询sql是下面这样:
select a,max(b) from t group by a。
如果有帮助到你,请点击采纳。
其实这个方法有问题应该这样写select table1_id,max(age) age from table2 group by table1_id
你的where条件 a.table1_id=table1_id是判断当前table1_id的值age是不是最大的
T是表,G是组,V是值:
分组、求和、求最大值:select G,MAX(SUM(V)) V1 from T group by G
求比值:
select T.G,SUM(T.V)/A.V1
from T,
(select G,MAX(SUM(V)) V1 from T group by G) A
where T.G=A.G
group by T.G
试试看,我没测试。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)