考虑一个示例SQL表,其中有两列和值插入为
INSERT INTO `over_all` (`team_number`, `day_1`) VALUES
('J091', '01:00:00'),
('J091', '01:02:00');
INSERT INTO `over_all` (`team_number`, `day_1`) VALUES
('J092', 'null'),
('J092', '02:02:00');
现在我使用
SELECT `over_all`.`team_number`,
max(`over_all`.`day_1`) as 'maximum'
FROM `over_all`
GROUP BY `over_all`.`team_number`
ORDER BY 'maximum'
问题:
我希望这能将J092的最大值返回为 null 。
使用数据库
服务器版本:10.1.25-MariaDB - mariadb.org二进制分发
答案 0 :(得分:2)
您可以使用CASE WHEN ... THEN ... ELSE ... END
:
SELECT team_number,
case when max(day_1 is null) = 0 then max(day_1) else null end as maximum
FROM over_all
GROUP BY team_number
ORDER BY maximum