SELECT (GREATEST((YEAR(NOW()) - GREATEST( M.MANUFACTURING_DATE,1900)), 0))
AS AGE,M.MANUFACTURING_DATE FROM table_name M;
上面是我的mysql查询,如果我认为MANUFACTURING_DATE = 0然后它将Age定为117,我想要一些解决方案,如果MANUFACTURING_DATE = 0,它应该使Age为0。
答案 0 :(得分:0)
您可以使用CASE状态:
SELECT
CASE
WHEN M.MANUFACTURING_DATE=0 THEN 0
ELSE (GREATEST((YEAR(NOW()) - GREATEST( M.MANUFACTURING_DATE,1900)), 0))
END
AS AGE,M.MANUFACTURING_DATE
FROM table_name M;