| 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 TrivediRank #16 · 50.3K reputationPosted Feb 21, 2012, 12:33 AM EST
Can u please give me more inforamtion about output?
Narayanan vd10 reputationPosted Feb 21, 2012, 1:13 AM EST
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 TrivediRank #16 · 50.3K reputationPosted Feb 21, 2012, 2:55 AM EST
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 vd10 reputationPosted Feb 21, 2012, 6:42 PM EST
Really its usefull...Thanks a lot
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 21, 2012, 6:52 PM EST
Wel come
any time...