Unix Technical Forum

Need help with query

This is a discussion on Need help with query within the DB2 forums, part of the Database Server Software category; --> I have a problem with following join: First query is generating RANK SELECT EMPNO,BONUS,(SELECT COUNT(*) + 1 FROM EMPLOYEE ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-04-2008, 06:23 AM
lenygold via DBMonster.com
 
Posts: n/a
Default Need help with query

I have a problem with following join:
First query is generating RANK
SELECT EMPNO,BONUS,(SELECT COUNT(*) + 1
FROM EMPLOYEE
WHERE BONUS > T.BONUS) AS RANK
FROM EMPLOYEE T
ORDER BY BONUS DESC;
EMPNO BONUS RANK
------ ----------- -----------
000010 1000.00 1
000110 900.00 2
000020 800.00 3
000030 800.00 3
000050 800.00 3
000070 700.00 6
000090 600.00 7
000120 600.00 7
000140 600.00 7
000200 600.00 7
000220 600.00 7
000240 600.00 7
000060 500.00 13
000100 500.00 13
........................................

and a query generating ROW_NUMBER

SELECT EMPNO, ROW# + 1 AS ROW_NUM
FROM EMPLOYEE TB1,
TABLE (SELECT COUNT(*) AS ROW# FROM EMPLOYEE TB2
WHERE TB2.EMPNO < TB1.EMPNO) AS TEMP_TAB;
EMPNO ROW_NUM
------ -----------
000010 1
000020 2
000030 3
000050 4
000060 5
000070 6
000090 7
000100 8
000110 9
000120 10
000130 11
000140 12
........................

Please help to constract a join to generate Bonus,Row_number and Rank

Thank's in advance. Leny G.

--
Message posted via http://www.dbmonster.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-06-2008, 02:04 PM
Serge Rielau
 
Posts: n/a
Default Re: Need help with query

lenygold via DBMonster.com wrote:
> I have a problem with following join:
> First query is generating RANK
> SELECT EMPNO,BONUS,(SELECT COUNT(*) + 1
> FROM EMPLOYEE
> WHERE BONUS > T.BONUS) AS RANK
> FROM EMPLOYEE T
> ORDER BY BONUS DESC;
> EMPNO BONUS RANK
> ------ ----------- -----------
> 000010 1000.00 1
> 000110 900.00 2
> 000020 800.00 3
> 000030 800.00 3
> 000050 800.00 3
> 000070 700.00 6
> 000090 600.00 7
> 000120 600.00 7
> 000140 600.00 7
> 000200 600.00 7
> 000220 600.00 7
> 000240 600.00 7
> 000060 500.00 13
> 000100 500.00 13
> .......................................
>
> and a query generating ROW_NUMBER
>
> SELECT EMPNO, ROW# + 1 AS ROW_NUM
> FROM EMPLOYEE TB1,
> TABLE (SELECT COUNT(*) AS ROW# FROM EMPLOYEE TB2
> WHERE TB2.EMPNO < TB1.EMPNO) AS TEMP_TAB;
> EMPNO ROW_NUM
> ------ -----------
> 000010 1
> 000020 2
> 000030 3
> 000050 4
> 000060 5
> 000070 6
> 000090 7
> 000100 8
> 000110 9
> 000120 10
> 000130 11
> 000140 12
> .......................
>
> Please help to constract a join to generate Bonus,Row_number and Rank

Which version of DB2 and which platform?
Note that DB2 for LUW supports OLAP functions for all supported
versions. There is no need for joins

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-06-2008, 02:04 PM
lenygold via DBMonster.com
 
Posts: n/a
Default Re: Need help with query

DB2 OS/390 V8.2. No OLAP functions. I am trying to developed them.
Thank's in advance>
Serge Rielau wrote:
>> I have a problem with following join:
>> First query is generating RANK

>[quoted text clipped - 44 lines]
>>
>> Please help to constract a join to generate Bonus,Row_number and Rank

>Which version of DB2 and which platform?
>Note that DB2 for LUW supports OLAP functions for all supported
>versions. There is no need for joins
>
>Cheers
>Serge
>


--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....m-db2/200803/1

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:26 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com