select ProductCode,InNum-OutNum from (select ProductCode,sum(a2) InNum from a group by ProductCode) m, (select ProductCode,sum(d3) OutNum from b group by ProductCode) n where m.ProductCode=n.ProductCode;
a2,d3就是数量了; 再把时间条件架上,就是你要的SQL语句了。
select invalue-nvl(outvalue,0),A.ProductCode from (select sum(nvl(A.数量,0)) invalue,ProductCode,createdate from A where to_char(createdate,'yyyymmddhh')=to_char(sysdate,'yyyymmdd')||'08' group by ProductCode) x, (select sum(nvl(B.数量,0)) outvalue,ProductCode,createdate from B where to_char(createdate,'yyyymmddhh')=to_char(sysdate,'yyyymmdd')||'08' group by ProductCode) y where a.ProductCode=b.ProductCode(+)
请问时间格式该怎么写? 我象这样写但是不成功 select ProductCode,InNum-OutNum from (select ProductCode,sum(a2) InNum from a where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss') group by ProductCode) m,(select ProductCode,sum(d3) OutNum from b where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss') group by ProductCode) nwhere m.ProductCode=n.ProductCode;而时间格式写成和bmws23lk(lk)一样却是通过的? 但是我用他的时间格式,和我的时间格式统计了一下入库表的数量是不一致的 我用的是 where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss'),这个也是符合实际的入库数量的 他用的是 where to_char(createdate,'yyyymmddhh')<to_char(sysdate,'yyyymmdd')||'08' 这一句难道是错了吗? 请问一下这两者有什么不同吗?
我用的是where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss'),----这里的createdate是varchar型的? 这个也是符合实际的入库数量的 他用的是 where to_char(createdate,'yyyymmddhh')<to_char(sysdate,'yyyymmdd')||'08' ---这里createdate是date型的,这2句表达意思不一样啊 再说to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss')这样写不对吧,截至到今天早上八点,我想你的意思应该是: where createdate < trunc(sysdate)+8/24 --createdate 是date类型
(select ProductCode,sum(a2) InNum from a group by ProductCode) m,
(select ProductCode,sum(d3) OutNum from b group by ProductCode) n
where m.ProductCode=n.ProductCode;
再把时间条件架上,就是你要的SQL语句了。
(select sum(nvl(A.数量,0)) invalue,ProductCode,createdate from A where to_char(createdate,'yyyymmddhh')=to_char(sysdate,'yyyymmdd')||'08' group by ProductCode) x,
(select sum(nvl(B.数量,0)) outvalue,ProductCode,createdate from B where to_char(createdate,'yyyymmddhh')=to_char(sysdate,'yyyymmdd')||'08' group by ProductCode) y
where a.ProductCode=b.ProductCode(+)
feng2(蜀山风云) 在二楼的Sql已经可以了。只要注意时间条件就行
我象这样写但是不成功
select ProductCode,InNum-OutNum from
(select ProductCode,sum(a2) InNum from a
where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss')
group by ProductCode) m,(select ProductCode,sum(d3) OutNum from b
where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss')
group by ProductCode) nwhere m.ProductCode=n.ProductCode;而时间格式写成和bmws23lk(lk)一样却是通过的?
但是我用他的时间格式,和我的时间格式统计了一下入库表的数量是不一致的
我用的是 where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss'),这个也是符合实际的入库数量的
他用的是 where to_char(createdate,'yyyymmddhh')<to_char(sysdate,'yyyymmdd')||'08'
这一句难道是错了吗?
请问一下这两者有什么不同吗?
这个也是符合实际的入库数量的
他用的是 where to_char(createdate,'yyyymmddhh')<to_char(sysdate,'yyyymmdd')||'08' ---这里createdate是date型的,这2句表达意思不一样啊
再说to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss')这样写不对吧,截至到今天早上八点,我想你的意思应该是:
where createdate < trunc(sysdate)+8/24 --createdate 是date类型
to_char(to_date(createdate,'yyyy-mm-dd hh24:mi:ss'),'yyyymmddhh24')<to_char(sysdate,'yyyymmdd')||'08'