Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 11 to 20 of 20 total |
Can I do this in SQL? |
Tue, Apr 3 2012 12:06 PM | Permanent Link |
John Hay | Ul
> > I am not an expert in SQL, but I fount this: > > http://rickosborne.org/blog/2008/01/sql-getting-top-n-rows-for-a-grouped-query/ > > Maybe it'll give you some hints how to proceed. > > Regards Uli A very elegant solution. John |
Tue, Apr 3 2012 12:23 PM | Permanent Link |
Uli Becker | John,
> A very elegant solution. I guess it was written by you using a pseudonym. Regards Uli |
Tue, Apr 3 2012 12:33 PM | Permanent Link |
John Hay | Uli Becker" <johnmuller54@googlemail.com> wrote in message
news:BF2096F3-14C7-43B1-BC65-7D7857D379BD@news.elevatesoft.com... > John, > > > A very elegant solution. > > I guess it was written by you using a pseudonym. I wish The use of a cartesian join in the solution did get me interested. For all but really large datasets there is no issue. If you do have a lot of different rows in each category (and I mean a lot!) it is possibble to use a combination of EDB's RUNSUM() and MIN() functions to get the same result, quicker without resorting to a join. The resulting sql is (nearly) unintelligible. Cheers John |
Wed, Apr 4 2012 3:45 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | John
Post it - I want to test my reading skills Roy Lambert |
Wed, Apr 4 2012 6:28 AM | Permanent Link |
John Hay | Roy
> Post it - I want to test my reading skills Have fun John select yearno,monthno,intnumber,username,temp-lowest+1 as rank from (select yearno,monthno,username,intnumber,runsum(1) as temp from (select extract(year from xdate) as yearno, extract(month from xdate) as monthno, Username,sum(intnumber) as intnumber from jobs group by yearno,monthno,username order by yearno,monthno,intnumber desc) t1 group by yearno,monthno,username,intnumber order by yearno,monthno,intnumber desc) t2 join (select yearno,monthno,min(temp) as lowest from (select yearno,monthno,username,intnumber,runsum(1) as temp from (select extract(year from xdate) as yearno, extract(month from xdate) as monthno, Username,sum(intnumber) as intnumber from jobs group by yearno,monthno,username order by yearno,monthno,intnumber desc) t3 group by yearno,monthno,username,intnumber) t4 group by yearno,monthno) t5 on t5.yearno=t2.yearno and t5.monthno=t2.monthno group by yearno,monthno,username,intnumber,rank having rank < 4 order by yearno desc,monthno desc,rank |
Wed, Apr 4 2012 7:02 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | John
You are one seriously sad individual Roy Lambert ps reading skills about year 2 |
Wed, Apr 4 2012 10:29 AM | Permanent Link |
Uli Becker | > select yearno,monthno,intnumber,username,temp-lowest+1 as rank from
> (select yearno,monthno,username,intnumber,runsum(1) as temp from > (select > extract(year from xdate) as yearno, > extract(month from xdate) as monthno, > Username,sum(intnumber) as intnumber from jobs > group by yearno,monthno,username > order by yearno,monthno,intnumber desc) t1 > group by yearno,monthno,username,intnumber > order by yearno,monthno,intnumber desc) t2 > join > (select yearno,monthno,min(temp) as lowest from > (select yearno,monthno,username,intnumber,runsum(1) as temp from > (select > extract(year from xdate) as yearno, > extract(month from xdate) as monthno, > Username,sum(intnumber) as intnumber from jobs > group by yearno,monthno,username > order by yearno,monthno,intnumber desc) t3 > group by yearno,monthno,username,intnumber) t4 > group by yearno,monthno) t5 > on t5.yearno=t2.yearno and t5.monthno=t2.monthno > group by yearno,monthno,username,intnumber,rank > having rank< 4 > order by yearno desc,monthno desc,rank Depressing! |
Wed, Apr 4 2012 10:50 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Uli
Over quoting Roy Lambert |
Mon, Apr 23 2012 2:39 AM | Permanent Link |
Lucian | Sorry for being so late (was renovating my house and was not on Delphi for quite some time):
Thank you very much! Lucian |
Mon, Apr 23 2012 3:26 AM | Permanent Link |
Lucian | >Have fun
Thank you John, it did the trick! Lucian |
« Previous Page | Page 2 of 2 | |
Jump to Page: 1 2 |
This web page was last updated on Sunday, May 5, 2024 at 10:18 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |