Reputation: 103
When I try to run a select statement with subqueries in mysql workbench I encounter an OK response with no results (the query is successful). I am sure the code is alright and mysql also doesn't find any error, but I don't know why I don't get any answer.
Here's the code
SELECT date(created_at),
(SELECT
SUM(amount) AS topup_amount
FROM
wallet_transaction
WHERE
type = 'topup'
GROUP BY DATE(created_at)),
(SELECT
SUM(amount) AS admin_add_amount
FROM
wallet_transaction
WHERE
type = 'admin_add'
GROUP BY DATE(created_at))
FROM
wallet_transaction;
Upvotes: 9
Views: 18858
Reputation: 108380
It looks like you are after the result produced by a query like this:
SELECT DATE(wt.created_at) AS dt_created
, IFNULL(SUM(IF(wt.type = 'topup' , wt.amount, 0)),0) AS topup_amount
, IFNULL(SUM(IF(wt.type = 'admin_add', wt.amount, 0)),0) AS admin_add_amount
FROM wallet_transaction wt
GROUP BY DATE(wt.created_at)
There are a couple of issues with the original query. The subqueries in the SELECT list can return at most one row, or MySQL will throw an error.
Upvotes: 10