| Input | OutPut | ||||
| Row | Person | row | person | Count | |
| 1 | 101 | 1 | 101 | 1 | |
| 1 | 102 | 1 | 102 | 1 | |
| 1 | 103 | 1 | 103 | 1 | |
| 2 | 101 | 2 | 101 | 2 | |
| 2 | 102 | 2 | 102 | 2 | |
| 2 | 104 | 2 | 103 | 1 | |
| 3 | 101 | 2 | 104 | 1 | |
| 3 | 103 | 3 | 101 | 3 | |
| 3 | 105 | 3 | 102 | 2 | |
| 3 | 103 | 3 | |||
| 3 | 104 | 1 | |||
| 3 | 105 | 1 | |||
Please find the logic to perform the below request withot using the while loops
Please find the logic to perform the below request withot using the while loops.
Jignesh TrivediPosted Feb 21, 2012, 11:52 PM
Wel come
any time...
Narayanan vdPosted Feb 21, 2012, 11:42 PM
Really its usefull...Thanks a lot
Jignesh TrivediPosted Feb 21, 2012, 7:55 AM
Try...
CREATE TABLE [dbo].[test](
[Row] [int] NULL,
[Person] [int] NULL
) ON [PRIMARY]
select * from(
select *, ROW_NUMBER()OVER(PARTITION BY Person ORDER BY row,person) as count from test
) A
order by A.Row,A.Person
out put...
Row Person count
1 101 1
1 102 1
1 103 1
2 101 2
2 102 2
2 104 1
3 101 3
3 103 2
3 105 1
Hope this help.
Narayanan vdPosted Feb 21, 2012, 6:13 AM
Row is consider as WEEK
Person-101,102 etc are the Person Id's
In First Week 101,102,103 are the Person ID's ,they listen the partcular programme then their count is 1 for all peoples
In Second Week we consider both first and Second week
101-listen the channel both first week and second week then their count is 2
102,-listen the channel both first week and second week then their count is 2
104 -they Listen the Programme in Second Week Only then their count is 1
103 -they Listen the Programme in first Week Only then their count is 1
Thanks & Regards
Narayanan
Jignesh TrivediPosted Feb 21, 2012, 5:33 AM
Can u please give me more inforamtion about output?