SSMS
 sql >> Database >  >> Database Tools >> SSMS

SQL:come ordinare i valori in categorie in ssms

Sembra che tu voglia:

SELECT ItemRelation, DocumentNum, DocumentYear, IsPromo
FROM [dbo].[promo_data]
WHERE CustomerType = 'XY' AND IsPromo = 1
GROUP BY ItemRelation, DocumentNum, DocumentYear, IsPromo
HAVING COUNT(*) = 1;

MODIFICA:

Per recuperare tutte le colonne, usa le funzioni della finestra:

SELECT *
FROM (SELECT pd.*,
             COUNT(*) OVER (PARTITION BY ItemRelation, DocumentNum, DocumentYear, IsPromo) as cnt
      FROM [dbo].[promo_data] pd
      WHERE CustomerType = 'XY' AND IsPromo = 1
     ) pd
WHERE cnt = 1;