Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query to display before specified date

I am trying to get the sum of all sale prices before a specified date, I have tried the following.

SELECT SUM (Sale_Price), Sale_Date
FROM sales
GROUP BY Sale_Price, Sale_Date
WHERE Sale_Date < '2015-10-12';

However I keep getting "SQL command not properly ended". Any help would be greatly appreciated.

like image 348
DSSmith Avatar asked Jun 01 '26 18:06

DSSmith


2 Answers

If you want the sum for all the dates, then you would use:

SELECT SUM(Sale_Price)
FROM sales
WHERE Sale_Date < DATE '2015-10-12';

You only need the GROUP BY if you want one row for each dae.

like image 83
Gordon Linoff Avatar answered Jun 03 '26 11:06

Gordon Linoff


SELECT Sale_Date, SUM(Sale_Price)
FROM sales 
WHERE Sale_Date < DATE '2015-10-12'
GROUP BY Sale_Date 
like image 45
juergen d Avatar answered Jun 03 '26 13:06

juergen d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!