View previous topic :: View next topic |
Author |
Message |
Martin Beginner

Joined: 20 Mar 2006 Posts: 133 Topics: 58
|
Posted: Mon Jun 25, 2007 5:14 am Post subject: Select rows based on average sum |
|
|
Hi All,
Here are snapshot of a DB2 table:
Code: |
Empl Num date of run loanamount
1 06/25/2007 0
1 05/25/2007 0
1 04/25/2007 0
--------------------------------------------
-------------------------------------
-------------------------------------------
1 06/25/2004 1000000
|
Now I need to write a query to select all the rows for this emplyee since he had loan history.
Can any one let me know how to do this ?
Primary keys are : Employee num, Dept name
- Mt |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Jun 25, 2007 6:31 am Post subject: |
|
|
Quote: |
Now I need to write a query to select all the rows for this emplyee since he had loan history. Can any one let me know how to do this ? |
How do you determine he had a loan history? If the table you mentioned has more than 1 row for each Employee Num can it be considered a loan history?
Quote: |
Primary keys are : Employee num, Dept name
|
Where is the Dept name column in the above snapshot?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Mon Jun 25, 2007 6:33 am Post subject: Select loan history for a specific employee |
|
|
Martin wrote: | Now I need to write a query to select all the rows for this emplyee since he had loan history. |
if DATE_OF_RUN indicates that he has a loan history
Code: |
SELECT EMPL_NUM
, DATE_OF_RUN
, LOANAMOUNT
FROM <table>
WHERE EMPL_NUM = 1
ORDER BY 2
|
The ORDER BY clause will sort your output chronologically. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
|
|