1
私のデータベースには3つのテーブルがあります。ここではそれがどのように見えるか:2つの左結合を結合する
tbl_production:
+--------+------------+-----+-------+
| id_pro | date | qty | stock |
+--------+------------+-----+-------+
| 1 | 2017-09-14 | 100 | 0 |
| 2 | 2017-09-15 | 150 | 0 |
| 3 | 2017-09-16 | 140 | 0 |
tbl_out:
+--------+------------+-----+
| id_out | date | qty |
+--------+------------+-----+
| 1 | 2017-09-14 | 50 |
| 2 | 2017-09-14 | 50 |
| 3 | 2017-09-15 | 50 |
| 4 | 2017-09-15 | 50 |
| 5 | 2017-09-15 | 50 |
| 6 | 2017-09-16 | 40 |
| 7 | 2017-09-16 | 50 |
| 8 | 2017-09-16 | 50 |
tbl_return:
+--------+------------+-----+
| id_ret | date | qty |
+--------+------------+-----+
| 1 | 2017-09-14 | 8 |
| 2 | 2017-09-14 | 0 |
| 3 | 2017-09-15 | 4 |
| 4 | 2017-09-15 | 0 |
| 5 | 2017-09-15 | 3 |
| 6 | 2017-09-16 | 3 |
| 7 | 2017-09-16 | 2 |
| 8 | 2017-09-16 | 0 |
私は
SELECT TRUNCATE(COALESCE(SUM(tbl_out.qty),0),0) AS Out, tbl_production.date FROM tbl_production LEFT JOIN tbl_out
ON (tbl_production.date = tbl_out.date) GROUP BY tbl_production.date;
このクエリに参加したいと思いますが
SELECT TRUNCATE(COALESCE(SUM(tbl_return.qty),0),0) AS ret FROM tbl_production LEFT JOIN tbl_return ON (tbl_production.date = tbl_return.date)GROUP BY tbl_production.date;
と
私が見たいと思った結果がこの
+--------+------------+-----+
| out | date | ret |
+--------+------------+-----+
| 100 | 2017-09-14 | 8 |
| 150 | 2017-09-15 | 7 |
| 140 | 2017-09-16 | 5 |
どのように私はこれを達成することができますようなものですか?