列和行(SQL)

时间:2017-08-11 03:12:24

标签: mysql sql

这是我的代码,

select concat(month(b.delivery_date), "/", year(b.delivery_date)) as month_year, b.company, sum(b.subtotal) as revenue 
from all_company a, all_order_summary b 
where a.company_id = b.company_id and a.paid = 1 and year(b.delivery_date) = 2017 
group by year(b.delivery_date), month(b.delivery_date)

打印出类似这样的内容:

MONTH_YEAR |公司收入

| 01/2017 | ABC123 | 500000

| 02/2017 | ABC123 | 100000

| 01/2017 | DEF456 | 300000

| 02/2017 | DEF456 | 800000

我希望它以这种方式打印,

[空间] 01/2017 | 02/2017

ABC123 | 500000 | 100000 |

DEF456 | 300000 | 800000 |

我该怎么做才能改变这个? (我对SQL比较新)

0 个答案:

没有答案