I have 2 queries that I would like to combine into one. Basically I want the 2 queries to be in one output table… output would look like this…
Store GC Sold Total Cars 1 22 75 2 24 88 3 15 89
The problem is I can’t figure out how to get it in the same table.
Here are my queries…
SELECT Store_Number, COUNT_BIG(Quantity_Sold) AS GC Sold
FROM Invoice_Detail_Tb
WHERE (Invoice_Date BETWEEN CONVERT(DATETIME, @startdate, 102) AND CONVERT(DATETIME, @enddate, 102)) AND (JLI_Category_Code = 'gc')
AND (Invoice_Detail_Code LIKE 'jlgc%') AND (Invoice_Detail_Type = 'Item')
GROUP BY Store_Number
This Output is:
Store Number GC Sold 1 12 2 13 3 14
SELECT Store_Number,
SUM(Vehicle_Count) AS [Total_Cars]
FROM Daily_Sales_Tb
WHERE (Operations_Day BETWEEN CONVERT (DATETIME, @startdate, 102) AND CONVERT (DATETIME, @enddate, 102))
GROUP BY Store_Number;
Output:
Store Number Total Cars 1 7 2 8 3 9
Separately, the queries work as designed. However if I try to combine them they are 2 different aggregate functions so it doesn’t work.
1 Answer