You can nest CASE
inside CASE
:
SELECT
`Person`,
`Code`,
CASE WHEN
`Problem` = "Large"
THEN
CASE WHEN
500 - (TIME_TO_SEC((TimeDiff(Now(),`Start`)/60))) < 0
THEN
0
ELSE
500 - (TIME_TO_SEC((TimeDiff(Now(),`Start`)/60)))
END
END AS TimeLeft
FROM Table1
WHERE `Code` = "1111";
Or, you can use the function GREATEST
that is specific to MySQL:
SELECT
`Person`,
`Code`,
CASE WHEN
`Problem` = "Large"
THEN
GREATEST(500 - (TIME_TO_SEC((TimeDiff(Now(),`Start`)/60))), 0)
END AS TimeLeft
FROM Table1
WHERE `Code` = "1111";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…