DSSmith
DSSmith

Reputation: 33

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.

Upvotes: 3

Views: 734

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269513

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.

Upvotes: 4

juergen d
juergen d

Reputation: 204746

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

Upvotes: 3

Related Questions