📜  SQL 服务器查询列是或否 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:27.306000             🧑  作者: Mango

代码示例1
SELECT  a.ID, a.FirstName, a.Lastname,
        CASE WHEN COUNT(b.CustID) > 0 THEN 'YES' ELSE 'NO' END AS HasOrders
FROM    Customer a
        LEFT JOIN Orders b
            ON a.ID = b.CustID        -- <<== the linking column on both tables
GROUP   BY a.ID, a.FirstName, a.Lastname