ITPUB??ì3
12月微软Hyper-V虚拟化沙龙主题征集
ITPUB论坛 » Oracle开发 » why the result is different?

标题: why the result is different?
离线 Arrayapple77
初级会员



精华贴数 0
个人空间 0
技术积分 58 (24919)
社区积分 0 (50300)
注册日期 2001-12-17
论坛徽章:0
      
      

发表于 2002-1-16 16:01 
why the result is different?

请教各位大侠:
在存储过程中调用
PHP code:


open c1 
for Que_Sql;

 
loop

         fetch c1 into p_empid
;

         exit 
when c1%notfound;

     
select name into p_name from tb_employee where employee_id=p_empid;

     
insert into tmp_2

     select

    p_empid
,p_name,

    
sum(decode(time,'01',ct,0)),sum(decode(time,'02',ct,0)),sum(decode(time,'30',ct,0)),sum(decode(time,'31',ct,0)),sum(decode(time,'tt',ct,0)),p_seq1

    from tmp_1

    where employee_id
=p_empid 

    group by employee_id
;

  
end loop;

统计一个月中每天的ct,其中tt是指按empid 分类一个月来ct 数的总计,结果发现所有ct数自动*2翻了一倍,单独执行select decode 语句发现结果正确,请问我错在哪儿?(不知道问题表达清楚没有,有人理我吗?)


只看该作者    顶部
离线 coolsword
落叶飘零


精华贴数 4
个人空间 0
技术积分 3754 (390)
社区积分 2672 (501)
注册日期 2001-10-13
论坛徽章:5
行业板块每日发贴之星     
      

发表于 2002-1-16 17:30 
层次有点儿乱,这里我不太明白:
PHP code:


insert into tmp_2

     select

    p_empid
,p_name,

    
sum(decode(time,'01',ct,0)),sum(decode(time,'02',ct,0)),sum(decode(time,'30',ct,0)),sum(decode(time,'31',ct,0)),sum(decode(time,'tt',ct,0)),p_seq1

    from tmp_1

    where employee_id
=p_empid 

    group by employee_id
;




__________________
No Name
只看该作者    顶部
离线 eric
中级会员


精华贴数 0
个人空间 0
技术积分 457 (4323)
社区积分 288 (1985)
注册日期 2001-10-17
论坛徽章:1
      
      

发表于 2002-1-16 19:13 
I think it should be
insert into tmp_2
     select   p_empid.p_name,
                 sum(decode(time,'01',ct,0)),
                 sum(decode(time,'02',ct,0)),
                 sum(decode(time,'30',ct,0)),
                 sum(decode(time,'31',ct,0)),
                 sum(decode(time,'tt',ct,0)),
                 p_seq1
         from tmp_1
      where employee_id=p_empid
    group by employee_id;

isn't it, apple 77?


__________________
-----------------------------------------------------不是我不明白,这世界变化快。
只看该作者    顶部
离线 apple77
初级会员



精华贴数 0
个人空间 0
技术积分 58 (24919)
社区积分 0 (50300)
注册日期 2001-12-17
论坛徽章:0
      
      

发表于 2002-1-17 09:13 
问题是这样的

我有一张表table1(time,employee_id,recordcontent)其中time的格式是YYYYMMDD HH:MI:SS,recordcontent是具体交易内容.现在我要统计每月1-31日各个员工的交易数,外加每个员工当月交易数小计以及每天的交易数小计,格式如下:
employee_id/1日/..../31日/小计
001            /36 /...../45  /100
...
total           /300/..../240/10000
我现在的做法是先生成tmp_1(time,employee_id,recordcount)其中time是01/02格式转换到天,数据包含所有员工当月纪录数的统计,按工号分组纪录数总计(既每个员工当月交易总数)按tt,employee_d,recordcount插入tmp_1,再用前贴方法,生成最后结果,但结果总是不对,这样做法是否很傻?有无更好方法.还有就是tmp_1我查过数据正确,但tmp_2的问题出在哪?
请各位赐教!谢谢


只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问