表A:如何查詢子類別
name | date | con
------------------------------
tv | 2017-07-01 | 1
tv | 2017-07-02 | 1
tv | 2017-07-03 | 1
tv | 2017-07-03 | 2
mobil | 2017-07-03 | 1
mobil | 2017-07-04 | 1
tablet | 2017-07-03 | 1
tablet | 2017-07-03 | 2
tablet | 2017-07-03 | 3
tableB的:
name | date | was
------------------------------
tv | 2017-07-01 | 15
mobil | 2017-07-03 | 50
mobil | 2017-07-04 | 15
tablet | 2017-07-04 | 30
結果表A(沒問題):
select name,
Group_concat(cons) as conA
from(
select name,
count(con) as cons
from tableA
where
date between '2017-07-01' and '2017-07-31'
GROUP BY con, name
HAVING con>0) q
GROUP BY name;
如何tableA
結合210 tableB
? 左加入 - >我沒有嘗試? 子類別 - >我沒有嘗試? 我應該怎麼辦
所需的輸出:
name | conA | wasB |
------- -------- --------
tv | 3,1 | 15 |
mobil | 4 | 65 |
tablet | 9,1,1 | 30 |
請更有可讀性問題 –