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查詢
- 7. 使用MySQL查詢與子查詢
- 8. MySQL查詢使用另一個查詢
- 9. MySQL查詢使用子查詢
- 10. 使用MySQL查詢中的查詢
- 11. 使MySQL查詢
- 12. 查詢中使用MySQL的
- 13. Mysql的使用查詢GROUP_CONCAT()
- 14. 使用連接mysql查詢
- 15. MySQL查詢:使用LEFT JOIN
- 16. MySQL查詢使用在PHP
- 17. MYSQL查詢使用AND或
- 18. 使用codeigniter的MySql查詢
- 19. 如何使用MySQL查詢
- 20. MySQL查詢使用和
- 21. 使用PHP MySQL查詢
- 22. 查詢使用MySQL更新
- 23. 絃斷/使用MySQL查詢
- 24. 如何使用MySQL查詢
- 25. 使用Ruby的MySQL查詢
- 26. 如何使用MySQL查詢
- 27. MySQL查詢:使用條件
- 28. 如何使用MySQL查詢
- 29. 使用SELECT MySQL查詢
- 30. MySQL GROUP_CONCAT使用子查詢
客戶名稱是唯一字段嗎? –
沒有客戶名稱是不唯一的 –