I am using postgres but I know T-SQL too so any answer anyone can give me ill be grateful and able to make the conversion. I am trying to run a query for my company that’s a car sales company. they sell cars all over the US primarily in OR and WA. I need to come up with a report that will allow me to return sales that are new for OR and new for Wa and then the problem I’m having is the sales for all the other states that are not OR or Wa. So right now im running a union with group by where one query is for WA and the other statement is for OR. I want the results to look really simple and just have 3 rows. 1 OR 1 WA and the 3rd row all the other states combined. I cant figure out how to combine the not equal to OR or WA into one single value. Is this even possible?
Thank you for taking the time to look at this
my query will also include used sale cars but I can integrate that once I figure out how to get this problem figured out so that’s why the query has multiple unions
Here’s my query I have now:
SELECT buyerstate AS "State",
Count(buyerstate) AS "Acura",
saletype AS "N/U"
FROM lydeal
WHERE stocklocationid = '8'
AND buyerstate = 'OR'
AND saledate > '8/01/12'
AND saletype = 'N'
GROUP BY buyerstate,
stocklocationid,
saletype
UNION
SELECT buyerstate AS "State",
Count(buyerstate) AS "Acura",
saletype AS "N/U"
FROM lydeal
WHERE stocklocationid = '8'
AND buyerstate = 'OR'
AND saledate > '8/01/12'
AND saletype = 'U'
GROUP BY buyerstate,
stocklocationid,
saletype
UNION
SELECT buyerstate AS "State",
Count(buyerstate) AS "Acura",
saletype AS "N/U"
FROM lydeal
WHERE stocklocationid = '8'
AND buyerstate = 'WA'
AND saledate > '8/01/12'
AND saletype = 'N'
GROUP BY buyerstate,
stocklocationid,
saletype
UNION
SELECT buyerstate AS "State",
Count(buyerstate) AS "Acura",
saletype AS "N/U"
FROM lydeal
WHERE stocklocationid = '8'
AND buyerstate = 'WA'
AND saledate > '8/01/12'
AND saletype = 'U'
GROUP BY buyerstate,
stocklocationid,
saletype
Try this