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 |
|
ramdas
Posting Yak Master
181 Posts |
Posted - 2003-09-04 : 11:16:50
|
| Hi folks,I have the following situation:A .000000 2003-07-01 00:00:00.000 1B .000000 2003-07-01 00:00:00.000 2D .000000 2003-06-02 00:00:00.000 52E .000000 2003-06-02 00:00:00.000 45How do I get the result set asB .000000 2003-07-01 00:00:00.000 2D .000000 2003-06-02 00:00:00.000 52I am sure there is some ranking logic involved, could someone give me an insight.Thank you in advance.Ramdas Ramdas NarayananSQL Server DBA |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2003-09-04 : 11:19:33
|
| If you provided column names then this would make more sense, but essentially you are afterSELECT col1, col2, max (col3) as col3FROMyourtable group by col1, col2You may find results vary if your dates are not exact matches.-------Moo. :) |
 |
|
|
ramdas
Posting Yak Master
181 Posts |
Posted - 2003-09-04 : 11:31:23
|
| Hi,The columns are employee,value,date and callcount. I need the results with the employee,value,date and the max of callcount for the particular day.Emp value date maxcallcountB .000000 2003-07-01 00:00:00.000 2D .000000 2003-06-02 00:00:00.000 52RamdasRamdas NarayananSQL Server DBA |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2003-09-04 : 11:35:00
|
| [code]select employee, value, date, callcountfrom ramdas rwhere not exists ( select 1 from ramdas where r.employee = employee and r.date = date and r.callcount < callcount)[/code] Jay White{0} |
 |
|
|
ramdas
Posting Yak Master
181 Posts |
Posted - 2003-09-04 : 11:42:24
|
| Hi Jay,I tried your query, but i am not getting the result set, I still get 2 records for a given day.Thank youRamdasRamdas NarayananSQL Server DBA |
 |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2003-09-04 : 12:47:19
|
See if this will work for you:SELECT a.Emp , a.value , a.date , b.callcountFROM yourtable a JOIN ( SELECT date, max(callcount) 'callcount' FROM yourtable GROUP BY date ) b ON a.date = b.date AND a.callcount = b.callcount |
 |
|
|
|
|
|
|
|