如何在MySQL select语句中编写条件?
我正在使用MySQL,我想在我的SQL中做一种三元语句,如:
SELECT USER_ID, ((USER_ID = 1) ? 1 : 0) AS FIRST_USER FROM USER
结果将类似于:
USER_ID | FIRST_USER 1 | 1 2 | 0 3 | 0 etc.
如何做到这一点?
SELECT USER_ID, (CASE USER_ID WHEN 1 THEN 1 ELSE 0 END) as FIRST_USER FROM USER
SELECT USER_ID, IF(USER_ID = 1, 1, 0) AS FIRST_USER FROM USER
IF()语句的作用与三元相似? :运营商。