1
A
回答
1
您可以使用此查询:
select
customerName,
coalesce(sum(case when month(`date`) = 1 then paidamount end), '-') as `January` ,
coalesce(sum(case when month(`date`) = 2 then paidamount end), '-') as `February`,
coalesce(sum(case when month(`date`) = 3 then paidamount end), '-') as `March`,
coalesce(sum(case when month(`date`) = 4 then paidamount end), '-') as `April`,
coalesce(sum(case when month(`date`) = 5 then paidamount end), '-') as `May`,
coalesce(sum(case when month(`date`) = 6 then paidamount end), '-') as `June`,
coalesce(sum(case when month(`date`) = 7 then paidamount end), '-') as `July`,
coalesce(sum(case when month(`date`) = 8 then paidamount end), '-') as `August`,
coalesce(sum(case when month(`date`) = 9 then paidamount end), '-') as `September`,
coalesce(sum(case when month(`date`) = 10 then paidamount end), '-') as `October`,
coalesce(sum(case when month(`date`) = 11 then paidamount end), '-') as `November`,
coalesce(sum(case when month(`date`) = 12 then paidamount end), '-') as `December`
from test
group by customerName
1
这是一个典型的表改变MySQL表的格式请点击以下链接:
select
customerName,
coalesce(max(case when month(`date`) = 1 then paidamount end), '-') as `January` ,
coalesce(max(case when month(`date`) = 2 then paidamount end), '-') as `February`,
coalesce(max(case when month(`date`) = 3 then paidamount end), '-') as `March`,
coalesce(max(case when month(`date`) = 4 then paidamount end), '-') as `April`,
coalesce(max(case when month(`date`) = 5 then paidamount end), '-') as `May`,
coalesce(max(case when month(`date`) = 6 then paidamount end), '-') as `June`,
coalesce(max(case when month(`date`) = 7 then paidamount end), '-') as `July`,
coalesce(max(case when month(`date`) = 8 then paidamount end), '-') as `August`,
coalesce(max(case when month(`date`) = 9 then paidamount end), '-') as `September`,
coalesce(max(case when month(`date`) = 10 then paidamount end), '-') as `October`,
coalesce(max(case when month(`date`) = 11 then paidamount end), '-') as `November`,
coalesce(max(case when month(`date`) = 12 then paidamount end), '-') as `December`
from yourtable
group by customerName
+0
其不给予每月支付金额的总和 –
+0
我使用sum()代替max()现在它工作正常谢谢 –
相关问题
- 1. 使用MySQL查询
- 2. MySQL查询使用子查询两次
- 3. 使用MySQL查询中的查询
- 4. MySQL查询使用子查询
- 5. 使MySQL查询
- 6. MySQL查询使用在PHP
- 7. MySQL查询:使用LEFT JOIN
- 8. 如何使用MySQL查询
- 9. MySQL查询:使用条件
- 10. 如何使用MySQL查询
- 11. MYSQL查询使用AND或
- 12. 使用SELECT MySQL查询
- 13. 使用PHP MySQL查询
- 14. 使用$ _GET的MySQL查询
- 15. 使用Ruby的MySQL查询
- 16. 使用加入mySQL查询
- 17. 使用MySQL的SQL查询
- 18. 重复使用mysql查询
- 19. 使用mysql无效的mysql查询
- 20. 使用mysql查询检查空结果
- 21. mysql查询查询
- 22. MySQL查询费用
- 23. MySQL查询 - 用源
- 24. 在mysql查询中运行mysql查询
- 25. MySQL查询笨查询
- 26. MYSQL查询相关查询
- 27. MySQL查询 - 加入查询
- 28. mysql查询子查询
- 29. 查询关闭查询MYSQL
- 30. Mysql查询JOIN查询
客户名称是唯一字段吗? –
没有客户名称是不唯一的 –