Need DB2 Query



IBM's flagship relational database management system

Need DB2 Query

Postby MFDEV » Sat Apr 23, 2016 1:31 pm

I need a query to get the following details :

For example, there are few rows with name 'DB2DB2' as

1 DB2DB2 X 10.00
2 DB2DB2 X 19.00
3 DB2DB2 X 27.00
4 DB2DB2 X 42.00
5 DB2DB2 Y 15.00
6 DB2DB2 M 10.00
7 DB2DB2 N 40.00

and a few other rows in the table like DB2DB2 so What I need is
The output should contains Sum of all X+Y MINUS Sum of all M+N = ?

Thanks in advance
MFDEV
 
Posts: 11
Joined: Mon Dec 01, 2014 3:25 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Need DB2 Query

 

Re: Need DB2 Query

Postby enrico-sorichetti » Sat Apr 23, 2016 5:12 pm

this is a HELP me to do something forum
not a DO IT FOR ME one

post what You have done, what issues You faced
and we will be glad to help
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2554
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 121 times

Re: Need DB2 Query

Postby MFDEV » Sun Apr 24, 2016 12:38 pm

Hi Enric,

Please see this query:

SELECT (SUM(A.COST) - SUM(B.COST)) AS DIFF
FROM T1 T, T1 B
WHERE T.NO=B.NO
AND T.NO='DB2DB2'
AND T.IND IN ('X','Y')
AND B.IND IN ('M','N')

I am expecting 63 as DIFF but output getting something else.

Thanks in advance
MFDEV
 
Posts: 11
Joined: Mon Dec 01, 2014 3:25 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Need DB2 Query

Postby prino » Sun Apr 24, 2016 4:59 pm

MFDEV wrote:Hi Enric,

His name in Enrico...
MFDEV wrote:I am expecting 63 as DIFF but output getting something else.

Probably 42, as that is the answer to everything...
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 494
Joined: Wed Mar 11, 2009 12:22 am
Location: Oostende, Belgium
Has thanked: 3 times
Been thanked: 19 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post