I would like to identify occurences where there are more than 1 distinct value of an E,F column combination within an A,B,C,D grouping.
For example, given the following data:
SELECT * FROM MyTable
A B C D E F
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 A B
1 1 1 1 A B
1 1 1 2 A C
1 1 1 2 A D
I want to return
A B C D
---------- ---------- ---------- ----------
1 1 1 2
..because there ar multiple distinct (E,F) combinations within that (A,B,C,D) grouping).
Here’s teh SQL to create your test case!
CREATE TABLE [dbo].[MyTable](
[A] [nchar](10) NULL,
[B] [nchar](10) NULL,
[C] [nchar](10) NULL,
[D] [nchar](10) NULL,
[E] [nchar](10) NULL,
[F] [nchar](10) NULL
) ON [PRIMARY]
GO
INSERT INTO [dbo].[MyTable]([A], [B], [C], [D], [E], [F])
SELECT N'1 ', N'1 ', N'1 ', N'1 ', N'A ', N'B ' UNION ALL
SELECT N'1 ', N'1 ', N'1 ', N'1 ', N'A ', N'B ' UNION ALL
SELECT N'1 ', N'1 ', N'1 ', N'2 ', N'A ', N'C ' UNION ALL
SELECT N'1 ', N'1 ', N'1 ', N'2 ', N'A ', N'D '
Edit: used wrong windowing function
Edit 2: clearer now with sample data