Table A fields:
- id
- date
- etc
Table B fields (contains detail items for each id in Table A):
- id
- idA (Table A id)
- items
- qty
我试图将每个项目的数量显示一周,就像这样。
RESULT:
- items
- qtydate1
- qtydate2
- qtydate3
- SUM(qty)
我该怎么做?
答案 0 :(得分:0)
这应该让你接近我想你想要的是什么? YEARWEEK()函数的改进空间可能会回到那个星期天的星期日吗?
SELECT b.items, YEARWEEK(a.date) AS week, SUM(b.qty)
FROM a
INNER JOIN b
ON a.id=b.idA
GROUP BY b.items, YEARWEEK(a.date)
ORDER BY b.items, week