Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
benmcr
Starting Member
1 Post |
Posted - 2010-08-31 : 20:13:49
|
| Table fields include logid,DeviceID, Meter, Date. my primary key is logid a log is made daily for each deviceid. exporting system has an error the meter will not change from one day to the next. to find these repeats i can go a few ways the way i feel is easiest would to count meter repeats but that limits the columns i can include. if i include date it makes all rows unique nothing gets counted is there a way to exclude this date column from the count funtion? Or is there a better way to find the last unique entry and date for each device would be more ideal?im generating this report for an account with 29 devicesexample data setdeviceid meter date1 5 1/12 6 1/13 9 1/11 5 1/22 8 1/23 11 1/21 5 1/32 9 1/33 11 1/3 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-08-31 : 21:09:35
|
you want to use a correlated subquery, or a CTE (common table expression).i don't have enough information to understand fully, but it sounds like you want to something like the followingSELECT t.*FROM yourTable tJOIN ( SELECT DeviceId, Max(date) dt FROM yourTable) xOn x.DeviceId = t.DeviceIdAnd t.date = x.dt If you could post the expected output, it would help us to be more specific. |
 |
|
|
|
|
|