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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-05-12 : 07:59:19
|
| i have a table called loghave firstname,datetimeI want to query the last record (based on datetime) for all records where there are an odd number of entries for todays dateso if i have joe 20100512 10:59jane 20100512 10:30joe 20100512 10:40jane 20100512 23:59joe 20100512 10:59joe 20100512 11:39john 20100512 11:39ken 20100512 11:39ken 20100512 12:39ken 20100512 15:39only john will show up and ken with the date of 20100512 15:39as the other have an even amount of entries can someone help me? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-05-12 : 08:05:51
|
[code]select *from ( select *, row_no = row_number() over (partition by firstname order by [datetime] desc), cnt = count(*) over (partition by firstname) from log ) lwhere cnt % 2 = 1and row_no = 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2010-05-12 : 08:08:59
|
| you still will need to filter for today |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-05-12 : 08:11:42
|
that should not be an uphill task for esthera right ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|