2

此查询从 linux cli 执行的 .sql 文件中运行良好。当我从 phpmyadmin 执行它时,它会启动一个睡眠进程,并且服务器上的 http 守护进程达到 99% 的 cpu 使用率,几分钟后查询由于“内部服务器错误”而失败。有任何想法吗?

 INSERT INTO Balance(id, Bal)
        SELECT a.id, SUM(a.Amount)
        FROM(
            SELECT ct.id, SUM(ct.Charges) as Amount
                FROM ChargesT ct
                GROUP BY ct.id  
        UNION ALL
            SELECT pt.id, -SUM(pt.PaymentAmt) as Amount
                FROM PaymentsT pt
                GROUP BY pt.id
            ) a
        GROUP BY a.id
4

1 回答 1

0

尝试删除子查询中的总和。我认为您可能可以在一个查询中做到这一点,但这是一个开始

 INSERT INTO Balance(id, Bal)
    SELECT a.id, SUM(a.Amount)
    FROM(
        SELECT ct.id, ct.Charges as Amount
            FROM ChargesT ct
        UNION ALL
        SELECT pt.id, -pt.PaymentAmt as Amount
            FROM PaymentsT pt
        ) a
    GROUP BY a.id
于 2013-11-22T10:45:02.447 回答