IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SQL qery for the below Scenario


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
a b c d

New User


Joined: 04 Mar 2010
Posts: 13
Location: UK

PostPosted: Fri Jul 16, 2010 4:13 pm
Reply with quote

Hi All,

My DB2 table looks as follows
Code:
Table T1
Col A   Col B   Col C
aaa     S1      100
bbb     S3      0
bbb             0
ccc     S2      50
ddd     P1      50
ddd             0


I need to report only those record where 1. Sum of the col C must be less than 100 or 2. Col B are spaces

Note - 1. For Sum of col C, I need to consider all records where col A are same. i.e for aaa sum=100, bbb=(0+0) = 0, ccc=50, ddd=(50+0)=50
2 - For Col B = spaces, I have to consider either off must be blank

In the above table except aaa record all other must be picked up
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Jul 16, 2010 4:19 pm
Reply with quote

Yes, and ................. is there a question in here somewhere or is this just a hope that you get a free solution.
Please show what you have already tried and the problems arising.

Also, learn to use the code tags as shown below
Code:
 [code] your
code     
   goes
       here  [/code]
Back to top
View user's profile Send private message
a b c d

New User


Joined: 04 Mar 2010
Posts: 13
Location: UK

PostPosted: Fri Jul 16, 2010 4:23 pm
Reply with quote

I tried with group by with no luck.....

I am looking for a query for the above scenario
Back to top
View user's profile Send private message
a b c d

New User


Joined: 04 Mar 2010
Posts: 13
Location: UK

PostPosted: Fri Jul 16, 2010 4:36 pm
Reply with quote

Hello Moderator,

How to put the code in code tag?????????
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 16, 2010 4:57 pm
Reply with quote

Here is an example from a db where the order_no has multiple line items,
each having a different prodkey. (I used 0, since prodkey is an integer)
to act like your column B = space.
price is amout, and i chose 6000 because that was convenient for my testing.

Code:

SELECT ORDER_NO
      ,sum(PRICE)
FROM AROMA.LINE_ITEMS P
WHERE EXISTS (SELECT ORDER_NO
              FROM AROMA.LINE_ITEMS S
              WHERE P.ORDER_NO = S.ORDER_NO
                AND S.PRODKEY = 0)
group by order_no HAVING SUM(PRICE) < 6000;


the CODE part of BBcode is explained here
Back to top
View user's profile Send private message
a b c d

New User


Joined: 04 Mar 2010
Posts: 13
Location: UK

PostPosted: Mon Jul 19, 2010 10:30 pm
Reply with quote

Thanks a lot Dick.....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts EMPTY file check scenario JCL & VSAM 6
No new posts Assistance required for WHEN=GROUP sc... JCL & VSAM 8
No new posts OUTREC S0C7 issue for particular scen... DFSORT/ICETOOL 6
No new posts ADRDSSU code scenario JCL & VSAM 3
No new posts Tricky scenario JCL & VSAM 5
Search our Forums:

Back to Top