I have been trying to limit the table rows in the following situation,
any suggestions will be appreciated.
we have table called tempTb has columns id, c_id, c_name, rating, date
columns.
id is an identity column.
date is a datetime column, the rest are varchar datatype.
Here is the table structure with sample data,
id c_id c_name rating date
1 ao amer onli 1 1/1/2002
2 ao amer onli 1 3/1/2002
3 ao amer onli 1 6/1/2002
4 ao amer onli 3 9/1/2002
5 ao amer onli 3 12/1/2002
6 ao amer onli 3 3/1/2003
7 ao amer onli 3 6/1/2003
8 ao amer onli 3 9/1/2003
9 ao amer onli 2 12/1/2003
10 ao amer onli 1 6/1/2004
11 ao amer onli 1 12/1/2004
12 xy xabs yasd 1 1/1/2002
13 xy xabs yasd 2 3/1/2002
14 xy xabs yasd 2 6/1/2002
15 xy xabs yasd 2 9/1/2002
16 xy xabs yasd 1 12/1/2002
17 xy xabs yasd 1 3/1/2003
18 xy xabs yasd 3 6/1/2003
19 xy xabs yasd 3 9/1/2003
20 xy xabs yasd 2 12/1/2003
21 xy xabs yasd 1 6/1/2004
22 xy xabs yasd 1 12/1/2004
From this table I need to select the rows with rating changes only,
i.e if two or three consecutive rows have same rating only the first
row should be selected.
the selection should look like...
id c_id c_name rating date
1 ao amer onli 1 1/1/2002
4 ao amer onli 3 9/1/2002
9 ao amer onli 2 12/1/2003
10 ao amer onli 1 6/1/2004
12 xy xabs yasd 1 1/1/2002
13 xy xabs yasd 2 3/1/2002
16 xy xabs yasd 1 12/1/2002
18 xy xabs yasd 3 6/1/2003
20 xy xabs yasd 2 12/1/2003
21 xy xabs yasd 1 6/1/2004
I was trying to do this by self-joining the table like....
select t1.* from tempTb t1, tempTb t2
where t1.id!=t2.id,
t1.c_id=t2.c_id,
t1.c_name=t2.c_name,
t1.rating!=t2.rating.
But this is generating cartesian products,
I have tried some other combinations after where clause with date colmn
wtc,
but none seems to give the required result.
so if anybody can guide me in the right direction I would appreciate
it.
Thanks alot,
Remote