I’m using the following SQL-Statement:
SELECT Col1, count(*) as Col2, Col3
FROM table1
WHERE WeekEnding = '08/26/2012'
GROUP BY Col1
To get
Col1 Col2 Col3
NY 2 2
FL 1 2
TX 1 2
NJ 1 2
WA 2 2
DE 1 3
MA 4 4
AL 3 3
How can I Exclude records where COL2 = COL3, so I get.
Col1 Col2 Col3
FL 1 2
TX 1 2
NJ 1 2
DE 1 3
You add
HAVING–havingworks after thegroupis done.Whereworks before thegroup.Note: You are grouping by Col1, but not Col3 – that isn’t legal since you are are requesting Col3 in the output.