I have 2 independent queries which are calculating the total IN/OUT of payments for a given festival. The IN/OUT is given by a ENUM value (see below).
If I run the queries independently it gives the correct output of SUM based on the selected payment_type IN or OUT. My problem is when I try to combine them in one query to have 2 separate columns for IN/OUT like below.
I have error in MySQL "Operand should contain 1 column(s)". After I've done some research I believe is the subqueries are wrong but I'm not quite sure how to solve it.
Thanks in advance for any help...
TOTAL IN
SELECT
SUM(`payment`.`pmt_amount`) AS `TOTAL IN`
, `payment`.`pmt_type`
, `festival`.`id_festival`
FROM
payment
INNER JOIN festival
ON (`payment`.`id_festival` = `festival`.`id_festival`)
WHERE (`payment`.`pmt_type` LIKE '%IN'
AND `festival`.`id_festival` = 1);
And TOTAL OUT
SELECT
SUM(`payment`.`pmt_amount`) AS `TOTAL OUT`
, `payment`.`pmt_type`
, `festival`.`id_festival`
FROM
payment
INNER JOIN festival
ON (`payment`.`id_festival` = `festival`.`id_festival`)
WHERE (`payment`.`pmt_type` LIKE '%OUT'
AND `festival`.`id_festival` = 1);
Combined
SELECT
festival.id_festival,
payment.pmt_amount,
payment.pmt_type,
(SELECT
payment.pmt_type,
SUM(payment.pmt_amount) AS `TOTAL OUT`
FROM payment
WHERE payment.pmt_type LIKE '%OUT'),
(SELECT
payment.pmt_type,
SUM(payment.pmt_amount) AS `TOTAL IN`
FROM payment
WHERE payment.pmt_type LIKE '%IN')
FROM payment
INNER JOIN festival
ON payment.pmt_amount = festival.id_festival
WHERE festival.id_festival = 1