Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select with max and min dates

Author  Topic 

cris001
Starting Member

2 Posts

Posted - 2014-11-22 : 10:10:28
Hello,
I´m struggling to get the following query:

Sales for the Last day of the month – sales for the last day of the previous month
Grouped by type and by month

Can anyone help please?
Many thanks!
Cris
______________________________________

DECLARE @sales TABLE
(type VARCHAR(10) NOT NULL,
date1 DATE NOT NULL,
sales NUMERIC(10, 2) NOT NULL);

INSERT INTO @sales(type, date1, sales)
VALUES ('q', '20140408', 51),
('q', '20140511', 3),
('q', '20140211', 3),
('q', '20140211', 5),
('q', '20140516', 3),
('q', '20140608', 3),
('q', '20140715', 3),
('q', '20140712', 3),
('q', '20140712', 3),
('q', '20140712', 3),
('q', '20140712', 4),
('q', '20140811', 3),
('q', '20140812', 1),
('q', '20140815', 5),
('q', '20140815', 6),
('q', '20140815', 2),
('q', '20140314', 7),
('q', '20140824', 1),
('q', '20140714', 24),
('q', '20140714', 24),
('x', '20140709', 25),
('x', '20140710', 16),
('x', '20140711', 36),
('x', '20140712', 23),
('x', '20140712', 35),
('x', '20140715', 57),
('c', '20140712', 97),
('c', '20140715', 71)




bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-11-22 : 13:58:14
looks very much like [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=197303[/url]
Go to Top of Page
   

- Advertisement -