Mysql返回OK但没有结果

时间:2016-05-14 20:11:14

标签: mysql

当我尝试在mysql workbench中运行带有子查询的select语句时,遇到没有结果的OK响应(查询成功)。我确信代码没问题,mysql也没有发现任何错误,但我不知道为什么我没有得到任何答案。

这是代码

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;

1 个答案:

答案 0 :(得分:2)

看起来你是在追查这样的查询产生的结果:

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)

原始查询存在一些问题。 SELECT列表中的子查询最多可以返回一行,否则MySQL将抛出错误。