Im looking for the fastest way to run a query that gets two different values from an Oracle table, and subtracts one from the other. The first is determined by querying a field that identifies one type of data, and the second by querying the same field for another type of data. The two individual queries are:
SELECT CDATE, TNAME, AS_REP
FROM CARD_TABLE
WHERE CDATE <= 01-Dec-2001
AND CDATE >= 01-Nov-2001
AND TNAME = TRSTXN
and
SELECT CDATE, TNAME, AS_REP
FROM CARD_TABLE
WHERE CDATE <= 01-Dec-2001
AND CDATE >= 01-Nov-2001
AND TNAME = TRS554N
These two queries will each return two rows, as there is one value on the first of each month. What I need is a query that would return two rows, but would give me the value of AS_REP from the first query minus AS_REP from the second query.
I have been trying to write subqueries, but I cant seem to get it right.
SELECT CDATE, TNAME, AS_REP
FROM CARD_TABLE
WHERE CDATE <= 01-Dec-2001
AND CDATE >= 01-Nov-2001
AND TNAME = TRSTXN
and
SELECT CDATE, TNAME, AS_REP
FROM CARD_TABLE
WHERE CDATE <= 01-Dec-2001
AND CDATE >= 01-Nov-2001
AND TNAME = TRS554N
These two queries will each return two rows, as there is one value on the first of each month. What I need is a query that would return two rows, but would give me the value of AS_REP from the first query minus AS_REP from the second query.
I have been trying to write subqueries, but I cant seem to get it right.