hi everyone,
i just cant figure out how to subtract fields in the same table.
Code:
SELECT
SUM( a.amountfigure ) AS 'Dollars'
, 'Buying' AS 'Transact'
FROM forex_tbl a
WHERE a.currency = 'USD' AND a.transactiontype = 'Buying'
UNION ALL
SELECT
SUM( b.amountfigure ) AS 'Dollars'
, 'Selling' AS 'Transact'
FROM forex_tbl b
WHERE b.currency = 'USD' AND b.transactiontype = 'Selling';
i want the 'Dollars' in buying be subtract to 'Dollars' in selling.
how can i do this.
thanks
ok i already get it...
Code:
SELECT
(SELECT
SUM( a.amountfigure ) AS 'Dollars'
FROM forex_tbl a
WHERE a.currency = 'USD' AND a.transactiontype = 'Buying') AS 'Buying'
,(SELECT
SUM( b.amountfigure ) AS 'Dollars'
FROM forex_tbl b
WHERE b.currency = 'USD' AND b.transactiontype = 'Selling') AS 'Selling';
whew....
any other solutions guys?
thanks