我有以下SQL,

SELECT SKU FROM Products WHERE SKU IN
(
   'SKU1',
   'SKU2',
   'SKU3',
   'SKU4',
   ......
   ......
   ......

   'SKUN',
)

我需要选择的是
 SKU    Exist
 ----------
 SKU1    Exist
 SKU2    NotExist
 SKU3    NotExist
 ................
 ................
 ................
 SKUN    NotExist

最佳答案

SELECT SKU,
    case when p.SKU is null then 'notExists' else 'exists' end [exists?]
FROM (VALUES
   ('SKU1'),
   ('SKU2'),
   ('SKU3'),
   ('SKU4'),
   ......
   ......
   ......

   ('SKUN')
) SKU(SKU)
left outer join Products p on p.SKU = SKU.SKU

10-07 15:40