I want to add the total sales by date using the HAVING SUM () variable but it is not working as expected.
SELECT
sum(SalesA+SalesB) as Sales,
sum(tax) as tax,
count(distinct SalesID) as NumOfSales,
Date
FROM
SalesTable
WHERE
Date >= '2014-03-01'
GROUP BY
Date, SalesA
HAVING
sum(SalesA+SalesB) >= 7000
ORDER BY
Date
The results are;
|Sales| tax | NumOfSales | Date |
10224| 345 | 1 |2014-03-06|
9224| 245 | 1 |2014-03-06|
7224| 145 | 1 |2014-03-06|
If I remove the SalesA in the GROUP BY clause it seems to ignore my HAVING sum clause and adds all the totals.
I would like the results to sum all by date like this .
|Sales| tax | NumOfSales | Date |
26672| 735 | 3 |2014-03-06
Thank you for any help you can provide.