因需要实现如下统计报表:
报表一: (三月份)
|产品名称 |本月| 本季|本年累计|
----------------------------
|氧气 |100 | 500| 500 |
----------------------------
|蒸汽 |300 | 400| 400 |
----------------------------
报表二:(三月份)
| | 厂 A | 厂 B |
-----------------------------------------------
|产品名称 |本月| 本季|本年累计| 本月|本季|本年累计 |
-----------------------------------------------
|氧气 |100 | 300| 300 | |200| 200 |
-----------------------------------------------
|蒸汽 |300 | 400| 400 | | | |
--------------------------------------------———
表的数据结构如下
name time num fact
------------------
氧气 2004-01 100 厂A
氧气 2004-02 100 厂A
氧气 2004-03 100 厂A
氧气 2004-02 200 厂B
蒸汽 2004-02 100 厂A
蒸汽 2004-03 300 厂Aname: 产品名称
time: 时间
num : 消耗量
fact : 厂名称
表一:是用来生成所有厂某种能源的消耗量统计
表二:是用来生成各个厂的所有能源的消耗量统计问两个个问题: 1。报表一的那种统计本季,本年的数据一般怎么实现?是不是先用存储过程
做好还是有别的什么方法?
2。报表二的把厂并排横向的方法如何做?
解决方案 »
- 关于用Delphi 从EXCEL 中导入图片以及从数据库中导出图片到excel 中,请大侠帮帮。
- 请问HOOK[0].STORE和HOOK[0].CHANGE分别是什么意思??
- ACCESS数据按规则顺序存储或提取的算法问题
- delphi7如何读取excel文件
- 远程SQL数据导入本地Access数据库
- 在DBGRID中如何知道鼠标双击到那条记录?
- 如何获得控件的句柄,是根据某特征值循环获得
- 敏感控件取值-UP有分
- 大家帮忙提供通用打印表格控件,我要做一个通用的打印表格的程序,谢谢了!
- 一个数据库里面存放着退了休的人员的资料 ,其中有夫妇,我想把夫妇从数据库里面找出来,
- 能否做到 当 鼠标 移动到 窗体 外 的 某个 特定 区域 时,激发窗体的事件??
- 在dbgrid中怎样将指针移到满足条件的记录上去?
直接用sql统计的话,统计本季好像部怎么好写把?
你有什么好的统计方法?
再直接弄到报表上打印...
/////////
直接用sql统计的话,统计本季好像部怎么好写把?
你有什么好的统计方法?
/////
没什么不好写啊.把你的表贴出来看看
------------------
氧气 2004-01 100 厂A
氧气 2004-02 100 厂A
氧气 2004-03 100 厂A
氧气 2004-02 200 厂B
蒸汽 2004-02 100 厂A
蒸汽 2004-03 300 厂A表名allot
select name,
(select count(num) from t as t2 where t1.name=t2.name and time>datediff(m,-1,getdate()),
(select count(num) from t as t2 where t1.name=t2.name and time>datediff(m,-3,getdate()),
(select count(num) from t as t2 where t1.name=t2.name and time>datediff(y,-1,getdate())
from t as t1
group by name
//for sql server2 与1 类似,在条件中加上 and fact = '厂A'
To : liuqifeiyu(liuqi)
没什么难的,你就说说怎么做的啊
如果是8月的话那么本季就应该统计的是7~8月
本年就应该统计1~8月
(select count(num) from t as t2 where t1.name=t2.name and year(time)=year(getdate()) and month(time)=month(getdate())),
(select count(num) from t as t2 where t1.name=t2.name and year(time)=year(getdate()) and (month(time)+1) / 3 =(month(getdate())+1) /3),
(select count(num) from t as t2 where t1.name=t2.name and year(time)=year(getdate()) ),
from t as t1
group by name
//for sql serveryear(time)=year(getdate()) and (month(time)+1) / 3 =(month(getdate())+1) /3
就是本季的
year(time)=year(getdate()) and (month(time)-1) / 3 =(month(getdate())-1) /3
就是本季的
统计季的方法好像不对把
如果是8月,应该就是统计7~9 月的总计把
(month(time)-1) / 3 =(month(getdate())-1) /3 这个条件可不可以统计两个月和三个月了
应为一季可能有三个月吧!请教了?