Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 10 of 20 total |
Can I do this in SQL? |
Thu, Mar 29 2012 12:08 PM | Permanent Link |
Lucian | Hi,
I have this query: SELECT EXTRACT(YEAR FROM XDate) as YearNo, EXTRACT(MONTH FROM XDate) as MonthNo, SUM(IntNumber) as IntNumber, UserName FROM jobs GROUP BY YearNo, MonthNo, UserName ORDER BY YearNo, MonthNo, IntNumber DESC It returns something like this: 2007 6 500 Paul.... 2007 6 399 Randy... 2007 6 345 Tom..... 2007 6 299 I don't want this row 2007 6 295 I don't want this row 2007 6 256 I don't want this row 2007 5 800 Greg.... 2007 5 689 Zoran... 2007 5 556 Edy..... 2007 5 398 I don't want this row 2007 5 201 I don't want this row 2007 4 700 Greg.... 2007 4 449 Randy... 2007 4 256 Tom..... 2007 4 198 I don't want this row 2007 4 101 I don't want this row However, I only want only the top 3 rows for each group Year, Month. Is it possible in SQL? TIA Lucian |
Thu, Mar 29 2012 2:56 PM | Permanent Link |
Uli Becker | Lucian,
ORDER BY YearNo, MonthNo, IntNumber DESC Just add Range 1 to 3 to your query. regards Uli |
Fri, Mar 30 2012 3:34 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Ulrich
>Just add > >Range 1 to 3 Does that work for each group? I thought it was for the query as a whole. Roy Lambert [Team Elevate] |
Fri, Mar 30 2012 4:36 AM | Permanent Link |
Uli Becker | Roy,
> Does that work for each group? I thought it was for the query as a whole. You are right: I should have read more carefully. Uli |
Fri, Mar 30 2012 4:37 AM | Permanent Link |
Lucian | >Range 1 to 3
As Roy pointed out, that does not work. regards Lucian |
Fri, Mar 30 2012 4:45 AM | Permanent Link |
Lucian | I have some old DBISAM code that I'm converting to ElevateDB. There, after running the query, I was manually removing unwanted records from the result ... this however is something that does not work in ElevateDB anymore.
|
Fri, Mar 30 2012 6:29 AM | Permanent Link |
Uli Becker | Lucian,
> As Roy pointed out, that does not work. 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 |
Fri, Mar 30 2012 8:02 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Uli
Brilliant link. Looks like a good book as well. I might just treat myself to a second hand copy unless we can persuade John Hay to write a DBISAM / ElevateDB specific one. Roy Lambert |
Fri, Mar 30 2012 8:07 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Lucian
>I have some old DBISAM code that I'm converting to ElevateDB. There, after running the query, I was manually removing unwanted records from the result ... this however is something that does not work in ElevateDB anymore. I personally think its sad that canned (non-sensitive) queries can't be edited. The options are now to create either a temporary table or an in-memory table and edit that. I've tended to use in-memory tables. A bit more difficult to create than with DBIASM but Tim gave me a script which I modified and now use. Temporary tables are a doddle to create (look up CREATE TEMPORARY TABLE) and the reason I don't use them is I like the self cleaning nature of in-memory tables in the event of a crash. Roy Lambert |
Sat, Mar 31 2012 2:49 AM | Permanent Link |
Uli Becker | Roy,
<< unless we can persuade John Hay to write a DBISAM / ElevateDB specific one. >> I'd like to place my order for that one without even knowing the price. Uli |
Page 1 of 2 | Next Page » | |
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 |