因需要实现如下统计报表:
报表一: (三月份)
        |产品名称  |本月| 本季|本年累计|
----------------------------
|氧气  |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。报表二的把厂并排横向的方法如何做?

解决方案 »

  1.   

    關鍵在於你的sql統計裡面,和報表的關係不大
      

  2.   

    To:Cheney(奥斯丁)
    直接用sql统计的话,统计本季好像部怎么好写把?
    你有什么好的统计方法?
      

  3.   

    在SQL里把数据先处理好.
    再直接弄到报表上打印...
    /////////
    直接用sql统计的话,统计本季好像部怎么好写把?
    你有什么好的统计方法?
    /////
    没什么不好写啊.把你的表贴出来看看
      

  4.   

    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     厂A表名allot
      

  5.   


    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'
      

  6.   

    from中的 t as t2 的as是什么意思呀 还没见过这样的用法 sql语句可以谴套的吗?
      

  7.   

    学习
    To : liuqifeiyu(liuqi) 
    没什么难的,你就说说怎么做的啊
      

  8.   

    没看懂 windindance(风舞轻扬)的意思
    如果是8月的话那么本季就应该统计的是7~8月
    本年就应该统计1~8月
      

  9.   

    select name,
    (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
    就是本季的
      

  10.   

    写错了
    year(time)=year(getdate()) and (month(time)-1) / 3 =(month(getdate())-1) /3
    就是本季的
      

  11.   

    To :windindance(风舞轻扬) 
    统计季的方法好像不对把
    如果是8月,应该就是统计7~9 月的总计把
      

  12.   

    To :windindance(风舞轻扬)
      (month(time)-1) / 3 =(month(getdate())-1) /3 这个条件可不可以统计两个月和三个月了
    应为一季可能有三个月吧!请教了?
      

  13.   

    用SQL做好统计,也就是你想要的数据源,该分组的分组,该分栏的分栏,如果没有合并单元格的就用FASTREPORT就行,如果报表需要合并相同内容的单元格,用REPORT MACHINE就搞定了。