Page 1 of 1

Need DB2 Query

PostPosted: Sat Apr 23, 2016 1:31 pm
by MFDEV
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

Re: Need DB2 Query

PostPosted: Sat Apr 23, 2016 5:12 pm
by enrico-sorichetti
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

Re: Need DB2 Query

PostPosted: Sun Apr 24, 2016 12:38 pm
by MFDEV
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

Re: Need DB2 Query

PostPosted: Sun Apr 24, 2016 4:59 pm
by prino
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...