Sum total of table with two related tables

前端 未结 2 680
情深已故
情深已故 2021-01-26 09:49

I\'m here with this (I\'m sure it is) simple question I can\'t figure out how to solve.

I have this schema:

<script

2条回答
  •  -上瘾入骨i
    2021-01-26 10:03

    SELECT p.name AS PERSON_NAME, 
        IFNULL(SUM(f.cost),0) AS TOTAL_FRUIT, 
        IFNULL(SUM(c.cost),0) AS TOTAL_COOKIE
    FROM person AS p
    LEFT JOIN fruit as f
        ON p.idperson = f.person_idperson
    LEFT JOIN cookie as c
        ON p.idperson = c.person_idperson
    GROUP BY p.idperson
    

提交回复
热议问题