|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2004-06-28 : 18:12:00
|
CREATE TABLE [dbo].[test] ( [p_id] [float] NULL , [ref_id] [float] NULL , [status] [nvarchar] (255) , [group] [nvarchar] (255), [change_status_date] [smalldatetime] ) ON [PRIMARY]GOinsert test values ( 1,1001,'Pending','H','2003-07-04')insert test values ( 1,1002,'Attend','L','2004-04-24')insert test values ( 2,1003,'Attend','H','2004-05-24')insert test values ( 3,1004,'Pending','L','2001-01-04')insert test values ( 3,1005,'Attend','H','2004-07-04')insert test values ( 4,1006,'drop','L','2004-07-08')insert test values ( 5,1007,'Pending','H','2004-01-04')insert test values ( 5,1008,'Attend','M','2004-07-04')insert test values ( 6,1009,'Pending','H','2004-01-04')insert test values ( 6,10010,'Attend','L','2004-01-01')insert test values ( 7,10011,'Pending','H','2003-07-04')insert test values ( 7,10011,'drop','H','2003-09-04')The table looks like:p_id ref_id status group change_status_date1 1001 pending H 3/24/20031 1002 Attend L 4/24/20042 1003 Attend H 5/24/20043 1004 pending L 1/4/20013 1005 Attend H 7/4/20044 1006 Attend H 7/8/20045 1007 Pending H 1/1/20045 1008 Attend M 2/2/20046 1009 Pending H 1/1/20046 1010 Drop L 3/2/20047 1011 Pending H 4/1/20047 1012 Attend L 7/1/2004 I would like to retrieve the P_ids ( person) who have the history of changing status: from pending to Attend. And, count it by group categories.First, retrive the p_ids who have different ref_ids, changed status(pending to Attend), and changed group category( H to L, L to H, or H to M). p_id ref_id status group change_status_date1 1001 pending H 3/24/20031 1002 Attend L 4/24/20043 1004 pending L 1/2/20043 1005 Attend H 7/4/20045 1007 Pending H 1/1/20045 1008 Attend M 2/2/20047 1011 Pending H 4/1/20047 1012 Attend L 7/1/2004 And count it by group categories.So, the final output should be:Group numberH to L 2L to H 1H to M 1 I am looking for the set based solution...any better idea? |
|