日期:2014-05-16  浏览次数:22041 次

mysql函数怎么嵌套
例如 sum(max(score)) 我想这样用 但是报错 请问怎么可以实现

------解决方案--------------------
select sum(x) from (select max(col) as x from t) a;
------解决方案--------------------
探讨

引用:

select sum(x) from (select max(col) as x from t) a;


对不起 忘了说了 只能是一个select 因为我还有其他的条件 如

select sum(x) from (select max(col) as x from t where t.userid = user.id) a;
……

------解决方案--------------------
分组错误,sum是分一组,max是分好几组(按你的意思),不一致,应该为select sum(m) from
(select max(..) m from ..);
------解决方案--------------------
sum(max(score))


select sum(ms)
from (
select username,max(score) as ms
from tb
group by username
)T