一张表t,物品价格表,今日新增了新物品,求今日价格与昨日对比后,显示所有物品的今日价格、与昨日对比
表t
id wp物品 rq日期 p价格
----------------------------
1 wp1 2010-3-1 10
2 wp1 2010-3-2 15
3 wp2 2010-3-2 20想要显示的结果
id wp rq p db与昨日对比
--------------------------------------
2 wp1 2010-3-2 15 +5
3 wp2 2010-3-2 20 求sql查询语句:
大侠们帮帮新手!
表t
id wp物品 rq日期 p价格
----------------------------
1 wp1 2010-3-1 10
2 wp1 2010-3-2 15
3 wp2 2010-3-2 20想要显示的结果
id wp rq p db与昨日对比
--------------------------------------
2 wp1 2010-3-2 15 +5
3 wp2 2010-3-2 20 求sql查询语句:
大侠们帮帮新手!
解决方案 »
- 怎样查看blob类型的数据?
- oracle存储过程的问题,是新手,不知道哪错了,希望大家给一下指点
- 我现在的表空间四个了,为什么每次导入全是占用NNC_DATA03.DBF
- 我的触发器错在何处?ORA-04091错误
- oracle中的一条sql语句,我看不懂。
- 在程序中触发触发器,第一次触发器没有执行完,就触发第二次,会怎么样?
- 触发器问题!
- 高手请进: 请问查询Oracle数据库中的表的含有Number型的字段时,为什么总是返回0?|
- 关于Oracle Develop6i的DEBUG问题
- db2存储过程与oracle存储过程的相互间的转换。大家谈谈,来者给分!
- oracle字符串比较问题
- 帮忙解读Function
from (
select id ,wp, rq, p,lag(order by rq group by wp) as pre_p
from t)
where pre_p is not null
FROM (SELECT t.* p - lag(p) over(PARTITION BY wp ORDER BY rq) db,
row_number() over(PARTITION BY wp ORDER BY rq DESC) rn
FROM t
WHERE t.rq >= trunc(SYSDATE) - 1)
WHERE rn = 1;
这个要在orcle10g下才可以运行的。
drop table t11;create table t11(
id number,
wp varchar(20),
cr date,
price number
);insert into t11
select 1, 'wp3', to_date('2010-4-6','yyyy-mm-dd'), 10 from dual union all
select 1, 'wp1', to_date('2010-4-5','yyyy-mm-dd'), 10 from dual union all
select 1, 'wp2', to_date('2010-4-5','yyyy-mm-dd'), 10 from dual union all
select 2, 'wp1', to_date('2010-4-6','yyyy-mm-dd'), 15 from dual union all
select 3, 'wp2', to_date('2010-4-6','yyyy-mm-dd'), 20 from dual;
commit;
select * from t11;select t1.*,(t1.price-t2.price) jiagecha
from (select t.* from t11 t where t.cr= trunc(sysdate)) t1
left join (select t3.* from t11 t3 where t3.cr<trunc(sysdate)) t2
on t1.wp=t2.wp
--and t1.cr>t2.cr
--and t1.cr>trunc(sysdate)
--and t2.cr<sysdate;-- 结果如下--
2 wp1 2010-4-6 15 5
3 wp2 2010-4-6 20 10
1 wp3 2010-4-6 10
select t1.*, decode((t1.price-t2.price),'','', '+'||(t1.price-t2.price)) jiagecha
from (select t.* from t11 t where t.cr= trunc(sysdate)) t1
left join (select t3.* from t11 t3 where t3.cr<trunc(sysdate)) t2
on t1.wp=t2.wp
lag(order by rq group by wp)?
应该是lag(p)over(partition by wp order by id)
SQL> edi
已写入 file afiedt.buf 1 select id,wp,rq,p-p1 from (select id,wp,rq,p,lag(p) over(partition by wp order by rq ) p1
2* from t) a
SQL> / ID WP RQ P-P1
---------- ----- -------------- ----------
1 wp1 01-3月 -10
2 wp1 02-3月 -10 5
3 wp2 02-3月 -10
一张表t,物品价格及销量表,当日新增了新物品,求当日价格与前一日对比后,显示所有物品的今日价格、价格与前一日对比、销量与前一日对比、截止当日当月的总销量(要求查询任意时间,比较有通用性)
表t
id wp物品 rq日期 p价格 xl销量
----------------------------
1 wp1 2010-3-1 10 5
2 wp1 2010-3-2 15 6
3 wp2 2010-3-2 20 12
4 wp1 2010-3-3 17 4
5 wp2 2010-3-3 19 15
想要显示的结果:查询2010-3-2的结果:
id wp rq查询的时间 p pdb xldb zxl当月总销量
--------------------------------------
2 wp1 2010-3-2 15 +5 +1 11
3 wp2 2010-3-2 20 空格 空格 12
求sql查询语句:
from (
select id ,wp, rq, p,lag(p)over(order by rq group by wp) as pre_p,
xl,lag(p)over(order by rq group by wp) as pre_xl
from t)
where pre_p is not null
and rq=to_date('2010-3-2')-1
如何求出
一张表t,物品价格及销量表,当日新增了新物品,求当日价格与前一日对比后,显示所有物品的今日价格、价格与前一日对比、销量与前一日对比、截止当日当月的总销量(要求查询任意时间,比较有通用性)一个表求出变化(数据重演,或者找change 时间戳,触发器)
在系统资源有限的情况下如何实现数据变话的动态分析!