每月分组最大值

时间:2013-05-06 15:02:31

标签: mysql group-by

我的表中包含以下列中的值:低,中,高和月。 我想得到以下每月最大值的结果。它将获取每月每列的最大值。

这是我的陈述

SELECT MAX(low) as Low,MAX(medium) as Medium,MAX(high) as High,month as mth FROM tablename WHERE month > 0;

期望的结果将是

month 1: Low 2 Medium 3 High 4

month 2: Low 4 Medium 2 High 5

month 3: Low 6 Medium 3 High 6

1 个答案:

答案 0 :(得分:1)

SELECT MAX(low) as Low,MAX(medium) as Medium,MAX(high) as High,month as mth 
FROM tablename 
WHERE month > 0
GROUP BY month
ORDER BY month;