杂数据报表的sql 编写求助?
sql吧
全部回复
仅看楼主
level 1
下图为日常录入数据格式,
现在想把某个时间段如:2012年1--3月的流水帐数据,按下表提取出来
请问有什么方法可以简单的实现(耗用系统资源最低),sql语句是否能实现,,请高人指点..
2012年11月21日 07点11分 1
level 13
只要有逻辑 SQL就一定可以实现
2012年11月21日 12点11分 2
level 1
怎么写啊,,有没有办法,求解..
2012年11月26日 08点11分 3
level 15
这不是excel报表吗,
lz
的报表根本不符合关系数据库的规范.
2012年11月27日 00点11分 4
我是用excel做的样式实例,就是想实现那种报表,有没有办法解决?
2012年12月03日 03点12分
level 6
可以 但是在数据库查询必须是两张表,A公司和B公司分开的两个也就是说A公司一个表 B公司一个表
2012年12月07日 05点12分 5
level 1
create table floatData
(
date datetime not null,
cal varchar(20),
name varchar(20),
quality varchar(20),
provider varchar(20),
weight int,
amount int
)
insert into floatData
select '2012-3-5','钢材','元钢','304','A',20,600
union all select '2012-3-6','钢材','元钢','304','B',25,500
union all select '2012-3-7','钢材','元钢','316','A',15,300
union all select '2012-3-5','钢材','元钢','304','A',30,900
union all select '2012-3-9','钢材','元钢','Q235','A',24,600
union all select '2012-3-5','钢材','元钢','316','B',25,1000
union all select '2012-3-11','钢材','元钢','304','A',26,500
SELECT * FROM FLOATDATA
;with a
as(
select date
,'总值' as '项目'
,SUM(case when provider='A' and quality='q235' then amount else null end)as 'Aq235'
,SUM(case when provider='A' and quality='304' then amount else null end)as 'A304'
,SUM(case when provider='A' and quality='316' then amount else null end)as 'A316'
,SUM(case when provider='B' and quality='q235' then amount else null end)as 'Bq235'
,SUM(case when provider='B' and quality='304' then amount else null end)as 'B304'
,SUM(case when provider='A' and quality='316' then amount else null end)as 'B316'
from floatData
GROUP BY date),
b
as(
select date
,'重量'as '项目'
,SUM(case when provider='A' and quality='q235' then weight else null end)as 'Aq235'
,SUM(case when provider='A' and quality='304' then weight else null end)as 'A304'
,SUM(case when provider='A' and quality='316' then weight else null end)as 'A316'
,SUM(case when provider='B' and quality='q235' then weight else null end)as 'Bq235'
,SUM(case when provider='B' and quality='304' then weight else null end)as 'B304'
,SUM(case when provider='A' and quality='316' then weight else null end)as 'B316'
from floatData
GROUP BY date
),
c
as
(SELECT a.date,
'均值' as '项目'
,case when a.Aq235 is not null then a.Aq235/b.Aq235 end as 'Aq235'
,case when a.A304 is not null then a.A304/b.A304 end as 'A304'
,case when a.A316 is not null then a.A316/b.A316 end 'A316'
,case when a.Bq235 is not null then a.Bq235/b.Bq235 end 'Bq235'
,case when a.B304 is not null then a.B304/b.B304 end 'B304'
,case when a.B316 is not null then a.B316/b.B316 end 'B316'
from a left join b on a.date=b.date
)
select * from (
select * from B
UNION ALL SELECT * FROM A
UNION ALL SELECT * from c) as d
order by 1;
2013年03月28日 09点03分 6
level 1
兄台,这个问题解决了么?如还需帮助请加qq 2051416768
2014年10月26日 04点10分 7
level 12
学习了
2017年09月16日 10点09分 8
1