SELECT
laporan.id AS id,
laporan.name AS name,
laporan.shell AS shell,
IFNULL(SUM(laporan_pengeluaran.harga),0) AS harga
FROM laporan
LEFT JOIN laporan_pengeluaran ON laporan.id=laporan_pengeluaran.laporan_id

网友答案:

Try this query

SELECT
l.id,
l.name,
IFNULL(lp.TCount,0) as Total
FROM laporan as l
LEFT JOIN (
SELECT
laporan_id,
SUM(harga) as TCount
FROM laporan_pengeluaran
GROUP BY laporan_id
) as lp ON lp.laporan_id = l.id