This is hard :) I try to SELECT date, GROUP BY date and count every column WHERE payment = 'cash' and 'card'
My table is something like this:
id | amount | payment_method | create_date
----------
1 | 10.00 | 'cash' | 2020-09-10
----------
2 | 15.00 | 'card' | 2020-09-10
----------
3 | 23.00 | 'cash' | 2020-09-11
I expect this type of results:
date | cash | card |
----------
2020-09-10 | 1 | 1 |
----------
2020-09-11 | 1 | 0 |
This one it's working for counting all payments:
SELECT DATE(op.create_date) AS cdate, COUNT(op.id) AS total
FROM order_payment op
GROUP BY cdate
And I try to work with this:
SELECT
DATE(op.create_date) AS cdate,
COUNT(
SELECT *
FROM order_payment
WHERE DATE(create_date) = rdate AND payment_method = 'cash'
) AS cash,
COUNT(
SELECT *
FROM order_payment
WHERE DATE(create_date) = rdate AND payment_method = 'card'
) AS card
FROM order_payment op
GROUP BY cdate
but it give me this error:
Query 1 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM order_payment o WHERE DATE(o.create_date) = rdate AND payment_me' at line 4
Someone can help me with this?