Q:

SUM SUBQUERY MySql

I have data:
2020/08/01  A   17
2020/08/01  A   17
2020/08/01  A   17
2020/08/02  A   17
2020/08/02  A   17
2020/08/02  A   17

I want data:
2020/08/01  A   17
2020/08/02  A   17

And sum:
A     34

How to sum them?
I've tried with this query, but failed
SELECT
SUM((SELECT
    TotCall
FROM
    mob_distribution
    JOIN krd_slsman ON krd_slsman.wh_id = mob_distribution.Wh_id
    JOIN krd_item ON krd_item.item_id = mob_distribution.Item_id 
WHERE
    krd_slsman.wh_parn = '103' 
    AND mob_distribution.Tanggal BETWEEN "2020-09-01" 
    AND "2020-09-03" 
GROUP BY
    mob_distribution.Tanggal 
ORDER BY
    mob_distribution.Wh_id ASC )) AS K
FROM
    mob_distribution AS a
    JOIN krd_slsman ON krd_slsman.wh_id = a.Wh_id
    JOIN krd_item ON krd_item.item_id = a.Item_id 
WHERE
    krd_slsman.wh_parn = '102' 
    AND a.Tanggal BETWEEN "2020-09-01" 
    AND "2020-09-03" 
GROUP BY
    a.Wh_id 
ORDER BY
    a.Wh_id ASC

A:

I'm making up names for the columns of your sample table.
SELECT type, SUM(num)
FROM (
    SELECT DISTINCT date, type, num
    FROM yourTable
) AS x
GROUP BY type

The subquery gets rid of all the duplicate rows, then the main query sums each group.

