Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If there is a Fee on Class Level then that fee overrides Fee on Course Level 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
US
The fees highlighted in red are the ones I need returned in the SELECT statement. Some classes will only have a "CLASS" or "COURSE" level but some will have both and if they have both then I only want to return the "CLASS" level.

Class Level Type Nbr Amt
[highlight #EF2929]TEST 101-1 CLASS 300001 $200[/highlight]
TEST 101-1 COURSE 300001 $300

[highlight #EF2929]TEST 102-1 COURSE 300002 $200[/highlight]

Help is appreciated!!!
 
This is what came to mind over morning coffee - others may have a more efficient approach. Not tested, but this should work:

Code:
SELECT Class, Level, Type, Nbr, Amt FROM fee_table WHERE type = 'CLASS'
UNION ALL
SELECT Class, Level, Type, Nbr, Amt FROM fee_table f
       INNER JOIN (SELECT nbr FROM fee_table WHERE type = 'COURSE'
                   MINUS 
                   SELECT nbr FROM fee_table WHERE type = 'CLASS') v
          ON v.nbr = f.nbr;

Hopefully, you have an index on your TYPE column.
 
Thanks Carp! I will try it tomorrow.
 
Hi carp,

It worked great! I really appreciate your help! Have a good day and be safe!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top