多条数据汇总SQL,在线等,求大神帮忙

huyajielovexiao 2014-09-04 09:57:29
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
...全文
305 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
huyajielovexiao 2014-09-04
  • 打赏
  • 举报
回复
引用 2 楼 mao5ge 的回复:
最终展示效果是什么?是变成一行?提问的时候,说清楚点啊。
根据class_code按year的不同汇总成一条数据
huyajielovexiao 2014-09-04
  • 打赏
  • 举报
回复
引用 2 楼 mao5ge 的回复:
最终展示效果是什么?是变成一行?提问的时候,说清楚点啊。
最终展示一条结果000000000001 2011-12 2733191377.00 210 2012-12 2843127052.93 215 2013-12 3108564663.53 224
BI-DA-刘恒 2014-09-04
  • 打赏
  • 举报
回复
最终展示效果是什么?是变成一行?提问的时候,说清楚点啊。
huyajielovexiao 2014-09-04
  • 打赏
  • 举报
回复
求大神指教,多谢了

6,108

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 数据库报表
社区管理员
  • 数据库报表社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧