多条数据汇总SQL,在线等,求大神帮忙
create table yearmonth (
yearmonth varchar(10) null
)
INSERT INTO yearmonth (yearmonth) VALUES('2014-09')
INSERT INTO yearmonth (yearmonth) VALUES('2013-12')
INSERT INTO yearmonth (yearmonth) VALUES('2012-12')
INSERT INTO yearmonth (yearmonth) VALUES('2011-12')
yearmonth
2014-09
2013-12
2012-12
2011-12
create table class_report (
class_code varchar(32) null ,
yearmonth varchar(10) null ,
all_price decimal(18,2) null ,
all_count int null
)
go
INSERT INTO class_report (class_code,yearmonth,all_price,all_count) VALUES('000000000001','2014-09',3287385351.42,229)
INSERT INTO class_report (class_code,yearmonth,all_price,all_count) VALUES('000000000001','2013-12',3108564663.53,224)
INSERT INTO class_report (class_code,yearmonth,all_price,all_count) VALUES('000000000001','2012-12',2843127052.93,215)
INSERT INTO class_report (class_code,yearmonth,all_price,all_count) VALUES('000000000001','2011-12',2733191377.00,210)
class_code, year, all_price all_count
000000000001 2014-09 3287385351.42 229
000000000001 2013-12 3108564663.53 224
000000000001 2012-12 2843127052.93 215
000000000001 2011-12 2733191377.00 210
最终展示效果
000000000001 2011-12 2733191377.00 210 2012-12 2843127052.93 215 2013-12 3108564663.53 224 2014-09 3287385351.42 229