select count(t.d502_00)
from d502 t
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'结果是:50
这个是正确的,但再添加一个条件之后就不正确了
select count(t.d502_00),sum(s.d504_09)
from d502 t,d504 s
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'
and t.d502_00 = s.d504_04结果:14441 444731.03
为什么会影响count(t.d502_00)的值呢? 而且现在取出的“14441”是符合条件的 d504 表中的行数。唉~~~头疼
from d502 t
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'结果是:50
这个是正确的,但再添加一个条件之后就不正确了
select count(t.d502_00),sum(s.d504_09)
from d502 t,d504 s
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'
and t.d502_00 = s.d504_04结果:14441 444731.03
为什么会影响count(t.d502_00)的值呢? 而且现在取出的“14441”是符合条件的 d504 表中的行数。唉~~~头疼
解决方案 »
- oracle 调用远程存储过程 并写入数据?DB LINK可以实现吗?可以调用远程数据库存储过程并且向远程数据库写入数据吗?麻烦贴下sql脚本demo解释下、谢
- 关于rollup 查询统计的问题
- 关于重新打开数据库后,package重新执行的问题
- sql 语句编写
- 请问哪里能下载到注册了的PL/SQL Developer软件???
- 如何在ORACLE中定义一个数组啊?
- 自增的问题
- pb如何调用oracle存储过程得到返回值
- 在VC++中调用OCI接口,为什么在编译的时候就会出现“OCI.Dll找不到指定的模块”的提示?
- 大家来帮忙呀,有谁知道oracle、slq server、pb和mysql都有些啥日志?
- 大数据表如何关联查询
- 如何獵取 年/月/日 中的日?
这个条件,2个表关联条件,对结果肯定有影响了
from d502 t,d504 s
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'
and t.d502_00 = s.d504_04(+)----------这里加一个左连接。
from d502 t,d504 s
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'
and t.d502_00 = s.d504_04(+)----------这里加一个左连接。
select (select count(tt.d502_00)
from d502 tt
where tt.d502_12 = '10000000000186'
and tt.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and tt.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and tt.d502_60 = '1'
and tt.d502_61 = '1')cnt,sum(s.d504_09)
from d502 t,d504 s
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'
and t.d502_00 = s.d504_04
with aa
as
(
select t.d502_00,s.d504_09,id
from d502 t,d504 s
where t.d502_12 = '10000000000186'
and t.d502_57 >= to_date('2011-07-01', 'yyyy-mm-dd')
and t.d502_57 <= to_date('2011-07-10', 'yyyy-mm-dd')
and t.d502_60 = '1'
and t.d502_61 = '1'
and t.d502_00 = s.d504_04(+)----------这里加一个左连接。
)select count(d502_00),sum(s.d504_09) from aa group by id