# IF 语句# SALES 部门发礼品A, 其余部门发礼品B, 打印每名员工获得的礼品SELECTe.ename, IF(d.dname="SALES","礼品A","礼品B") AS giftFROM t_emp e LEFT JOIN t_dept d ON e.deptno=d.deptno ;
CASE - WHEN 语句
# CASEWHEN 语句# SALES 部门去P1, ACCOUNTING 部门去P2, RESEARCH部门去P3SELECTe.ename,CASEWHEN d.dname="SALES"THEN"P1"WHEN d.dname="ACCOUNTING"THEN"P2"WHEN d.dname="RESEARCH"THEN"P3"ENDAS placeFROM t_emp e LEFT JOIN t_dept d ON e.deptno=d.deptno ;