我在mysql数据库中有一个表,我必须通过indicator_id从多列中获取最低和最高值,
表数据数据如
Indicator_id threshold_id colour Strat_value End_value
2004 1 Green 2 2
2004 2 Amber 1 1
2004 3 Red 0 0
2004 4 Black -1 -10
我使用了以下代码但未获得正确的结果
select indicator_id,
least(Start_value,End_value) low,
greatest(Start_value,End_value) high
from shrewd_db.threshold
group by id_indicator;
任何帮助将不胜感激。 感谢
答案 0 :(得分:1)
<强> SQL DEMO 强>
SELECT `Indicator_id`,
LEAST(MIN(`Strat_value`), MIN(`End_value`)) as smallest,
GREATEST(MAX(`Strat_value`), MAX(`End_value`)) as biggest
FROM Table1
GROUP BY `Indicator_id`
<强>输出强>