SELECT
incMonth as Month,
SUM( IF(item_type IN('typ1', 'typ2') AND incMonth = Month, 1, 0 ) )AS 'Total Sales'
FROM tester
Run Code Online (Sandbox Code Playgroud)
我只需要当月的总和来循环.
如果我正确阅读,你需要使用group-by或至少where子句将事物限制在你想要的时间范围内:
SELECT incMonth AS Month, SUM(IF(item_type IN('typ1', 'typ2'), 1, 0)) AS 'Total Sales'
FROM tester
GROUP BY incMonth
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14444 次 |
| 最近记录: |