SELECT * FROM EMPLOYEE_PAY_TBL; +-----------+---------------+------------+----------+-----------------+----------+---------+ | EMP_ID | POSITION | DATE_HIRE | PAY_RATE | DATE_LAST_RAISE | SALARY | BONUS | +-----------+---------------+------------+----------+-----------------+----------+---------+ | 213764555 | SALES MANAGER | 2004-08-14 | NULL | 2009-08-01 | 30000.00 | 2000.00 | | 220984332 | SHIPPER | 2006-07-22 | 11.00 | 1999-07-01 | NULL | NULL | | 311549902 | MARKETING | 1999-05-23 | NULL | 2009-05-01 | 40000.00 | NULL | | 313782439 | SALSEMAN | 2007-06-28 | NULL | NULL | 20000.00 | 1000.00 | | 442346889 | TEAM LEADER | 2000-06-17 | 14.75 | 2009-06-01 | NULL | NULL | | 443679012 | SHIPPER | 2001-01-14 | 15.00 | 1999-01-01 | NULL | NULL | +-----------+---------------+------------+----------+-----------------+----------+---------+ SELECT EMP_ID, COALESCE(BONUS, SALARY, PAY_RATE) FROM EMPLOYEE_PAY_TBL; -- 接受一个数据集,依次检查其中每一个值,直到发现一个非NULL值。如果没有找到非NULL值,返回一个NULL值 +-----------+-----------------------------------+ | EMP_ID | COALESCE(BONUS, SALARY, PAY_RATE) | +-----------+-----------------------------------+ | 213764555 | 2000.00 | | 220984332 | 11.00 | | 311549902 | 40000.00 | | 313782439 | 1000.00 | | 442346889 | 14.75 | | 443679012 | 15.00 | +-----------+-----------------------------------+
时间: 2024-10-12 02:30:39