Sunday, August 3, 2014

Use of SUM and COUNT with GROUP BY

I used this DDL+DML which is not like yours exectly



if OBJECT_ID('T','U') is not NULL drop table T
create table T(
[State] varchar(10)
,[DOB] datetime
,[StartDt] datetime
,[EndDt] datetime
,[Desc] varchar(10)
,[Category] varchar(10)
,[MemberID] int
,[SubID] int
,[Code] int
)

insert T ([State], DOB, StartDt, EndDt, [Desc], [Category], MemberID, SubID, Code)
values
('NC', '2003-01-30', '2014-01-01', '2014-01-31', 'Child', 'B', 123456, 2, 38),
('NC', '2003-01-30', '2014-01-01', '2014-01-31', 'Child', 'B', 123456, 2, 39),
('NC', '2003-01-30', '2014-02-01', '2014-05-31', 'Child', 'B', 123456, 2, 38),
('NC', '2003-01-30', '2014-02-01', '2014-05-31', 'Child', 'B', 123456, 2, 39),
('NC', '2003-01-30', '2014-06-01', '2014-07-31', 'Child', 'B', 123456, 2, 38),
('NC', '2003-01-30', '2014-06-01', '2014-07-31', 'Child', 'B', 123456, 2, 39),
('NC', '2014-01-17', '2014-01-01', '2014-07-31', 'Infant', 'S', 456789, 1, 49),
('NC', '2014-02-04', '2014-02-01', '2014-07-31', 'Infant', 'S', 246376, 3, 49)





[Personal Site] [Blog] [Facebook]signature


No comments:

Post a Comment