mysql中的Pivot表查询
在这种情况下,有没有办法在mysql中进行查询 我有一张桌子mysql中的Pivot表查询,mysql,pivot,Mysql,Pivot,在这种情况下,有没有办法在mysql中进行查询 我有一张桌子 group_name | cost_period | books_cost | others_cost group_A | 1/01/2015 | 100 | 200 group_A | 1/02/2015 | 56 | 86 group_A | 1/01/2015 | 22 | 222 group_A | 1/03/2015 | 30
group_name | cost_period | books_cost | others_cost
group_A | 1/01/2015 | 100 | 200
group_A | 1/02/2015 | 56 | 86
group_A | 1/01/2015 | 22 | 222
group_A | 1/03/2015 | 30 | 40
group_B | 1/02/2015 | 50 | 10
group_B | 1/02/2015 | 45 | 10
group_B | 1/01/2015 | 22 | 15
group_C | 1/02/2015 | 45 | 20
我希望它在查询后具有这种格式
JAN-2015 FEB-2015 MAR_2015 total
group_A
sum of book cost 122 56 30 208
sum of others cost 422 86 40 548
group_B
sum of book cost 22 95 0 117
sum of others cost 15 20 0 45
group_C
sum of book cost 0 45 0 45
sum of others cost 0 20 0 20
有没有一种方法可以通过查询来避免在收集数据后使用透视工具?因为jasper的交叉标签没有那么灵活
谢谢我认为您提出的方法不可能直接在数据库中执行,可能的是生成两个结果,一个是图书成本,另一个是其他成本,其中每列为月份,每行为一组。您可以接受这样的建议吗?您好@piotrgajow,谢谢您的建议,但我认为pivot查询可以做到这一点,我尝试了一些策略,但仍然缺少分组方面的一些关键部分。希望一位枢轴专家能帮助我。