ThePsion5 Posted December 11, 2007 Share Posted December 11, 2007 Hi,I'm trying to create an SQL statement that will return the total amount of money earned in a specific time period such as per day/per week/ per month. Here's the relevant table columns: table(amount INT NOT NULL,insert_dt DATETIME NOT NULL) And here's the SQL statement I want to use: SELECT SUM(amount) FROM table GROUP BY ? I seem to recall that this is possible, but how? Unfortunately my SQL is a bit rusty. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 11, 2007 Share Posted December 11, 2007 SELECT SUM(amount) FROM table WHERE insert_dt BETWEEN date1 AND date2 Link to comment Share on other sites More sharing options...
ThePsion5 Posted December 11, 2007 Author Share Posted December 11, 2007 SELECT SUM(amount) FROM table WHERE insert_dt BETWEEN date1 AND date2I'm trying to get an entire series of dates, though, not just a single date. For example:Month | AmountJanuary | 25February | 40March | April | 35May | 30June | 40... Link to comment Share on other sites More sharing options...
justsomeguy Posted December 11, 2007 Share Posted December 11, 2007 SELECT MONTH(insert_dt), YEAR(insert_dt), SUM(amount) FROM table GROUP BY YEAR(insert_dt), MONTH(insert_dt), Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.