| Author |
Topic |
|
Deepak1983
Starting Member
23 Posts |
Posted - 2010-12-10 : 13:34:23
|
| Mean Date3.8 7/1/2010 0:003.8 7/2/2010 0:002.1 7/3/2010 0:002.1 7/5/2010 0:003.8 7/6/2010 0:004.1 7/7/2010 0:004.1 7/8/2010 0:002.1 7/9/2010 0:00This is my table and i want result below :- Mean Date3.8 7/1/2010 0:002.1 7/3/2010 0:003.8 7/6/2010 0:004.1 7/7/2010 0:002.1 7/9/2010 0:00This means i only want rows where the value gets change for first time.Deeps |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-10 : 13:40:57
|
select mean, min(date) as date from table group by mean No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Deepak1983
Starting Member
23 Posts |
Posted - 2010-12-10 : 13:42:58
|
Well it will not give accurate result, it will not show the same value second time, for example 2.1 of 7/9/2010 again in the query you provided..quote: Originally posted by webfred select mean, min(date) as date from table group by mean No, you're never too old to Yak'n'Roll if you're too young to die.
Deeps |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-10 : 13:46:58
|
That's not possible unless your data has changed between first and second execution. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-10 : 13:49:12
|
Ah! Now I understand... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Deepak1983
Starting Member
23 Posts |
Posted - 2010-12-10 : 13:50:06
|
I just want the value changes for first time. Immaterial of what the value is?quote: Originally posted by webfred That's not possible unless your data has changed between first and second execution. No, you're never too old to Yak'n'Roll if you're too young to die.
Deeps |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-12-10 : 14:15:56
|
| ;with cte_MeanAS(SELECT Mean,Date,[Row] = row_number() OVER( order by date)FROM @table)select t1.*from cte_mean t1left join cte_mean t2 on t1.row = t2.row + 1 and t1.mean = t2.meanwhere t2.mean is nullJimEveryday I learn something that somebody else already knew |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-10 : 14:16:53
|
select dt1.mean, dt1.date from(select row_number() over (order by date asc) as rownum,* from table)dt1left join (select row_number() over (order by date asc) as rownum,* from table)dt2on dt1.rownum = dt2.rownum+1 and dt1.mean = dt2.meanwhere dt2.mean is null No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-10 : 14:18:01
|
wow   No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-10 : 14:19:01
|
Your CTE looks more elegant because you need to build that table only once... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-12-10 : 14:19:26
|
| Where can I get me one of those yak blasters?jimEveryday I learn something that somebody else already knew |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-10 : 14:23:10
|
ask graz? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-12-10 : 14:27:23
|
| I certainly hope I don't have to earn it!Thanks,JimEveryday I learn something that somebody else already knew |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-12-10 : 15:09:15
|
Type [ s n i p e d ] without the spaces |
 |
|
|
Deepak1983
Starting Member
23 Posts |
Posted - 2010-12-14 : 13:05:29
|
| Guys you are rockers.... superb... Thanks A lots.. its really helping me out..Deeps |
 |
|
|
|