Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下查询:
SELECT e.ename , e.empno, m.ename as manager FROM emp e LEFT OUTER JOIN emp m ON e.mgr = m.empno;
列出员工姓名、员工编号和他们的经理,并列出没有任何经理的员工。就我而言,总统没有任何经理。如果是总裁雇员,我想在经理列中提到 NONE,因为他没有任何经理。如何在上述查询中实现这一点?
谢谢
您可以将 替换null为noneusing COALESCE:
null
none
COALESCE
SELECT e.ename, e.empno, coalesce(m.ename, 'none') as manager FROM emp e LEFT OUTER JOIN emp m ON e.mgr = m.empno;
请参阅带有演示的 SQL Fiddle