MySql - 如何在符合条件时设置新值?

时间:2016-05-23 18:57:12

标签: mysql

SELECT ID, Division, EffectiveDate, PM, Status, Name, Address, ProjectType
FROM intranet.t_bidinfo
WHERE Division = 'TI'
AND EffectiveDate >= curdate()
AND Status = 1
ORDER BY EffectiveDate ASC
;

我需要在我的sql语句中将Status的返回值更改为'Active'而不是1,我将如何正确地执行此操作?

1 个答案:

答案 0 :(得分:0)

用例陈述:

SELECT ID, Division, EffectiveDate, PM, case Status when 1 then 'Active' end as Status, Name, Address, ProjectType
FROM intranet.t_bidinfo
WHERE Division = 'TI'
AND EffectiveDate >= curdate()
AND Status = 1
ORDER BY EffectiveDate ASC
;