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

SQL:So sortieren Sie Werte in Kategorien in ssms

Sie scheinen zu wollen:

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

BEARBEITEN:

Um alle Spalten abzurufen, verwenden Sie die Fensterfunktionen:

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;