SELECT IFNULL(p.name, sp.payment) as payment_name, SUM(sp.amount) as amount FROM trm_in_pos cr INNER JOIN trm_out_shift_payments sp ON sp.cash_id = cr.cash_id LEFT JOIN trm_in_payments p ON p.id = sp.payment AND p.store_id = cr.store_id WHERE cr.cash_id = ? AND sp.id = (?-1) GROUP BY IFNULL(p.name, sp.payment) ORDER BY IFNULL(p.name, sp.payment)
SELECT IFNULL(p.name, sp.payment) as payment_name, SUM(sp.amount) as amount FROM trm_in_pos cr INNER JOIN trm_out_shift_payments sp ON sp.cash_id = cr.cash_id LEFT JOIN trm_in_payments p ON p.id = sp.payment AND p.store_id = cr.store_id WHERE cr.cash_id = ? AND sp.id = (?-1) GROUP BY IFNULL(p.name, sp.payment) ORDER BY IFNULL(p.name, sp.payment)