求个思路——
问题描述:查询某日期下(),某用户的余额,要求:如果此用户今天没有,则查昨天的,昨天没有再查前天的
头大
问题描述:查询某日期下(),某用户的余额,要求:如果此用户今天没有,则查昨天的,昨天没有再查前天的
头大
解决方案 »
- c# 调用过程,报 {"ORA-01036: 非法的变量名/编号\n"} ,请帮忙
- 如何跟踪sybase数据库正在执行的语句
- 在存储过程中如何返回结果集
- 关于ORACLE内存表的问题
- 我使用<oracle9i>< pl/sql >出现了ORA-03113: 通信通道的文件结束
- 数据导入,出现ORACLE 的 922 错误,请帮忙解答,谢谢大家
- 非灌水:人生三境界与it技术,你看到了什么?
- 做数据库,用delphi+oracle,从哪里入手比较好?tks
- 关闭用户连接
- ORACLE变量定义问题
- 怎么在查询结果中重命名列名如“ Customer Full Name”呢?
- 目前能替代SQLPLUS最好的工具是什么啊
select .... from table where date <= 'XXX' and rownum=1
name time money
a 20111117 1
a 20111118 2
a 20111116 5
a 20111113 7
b 20111111 10
b 20111120 9
c 20111116 5
c 20111114 3 就像这种数据,比如查2011115的 应该是a 20111113 7
b 20111111 10
c 20111114 3
当然还可以再换日期 ,如2011113,则结果又是不一样求个思路,
不对的,请看看我的数据
select max(time) from table where date <= 'XXX'
不过顶cosio 的方法
select t1.* from table t1 ,(select name , max(time) max_t from table where time <='XXX' group by name )t2 where t1.name =t2.name and t1.time =t2.max_t
(select t.*,row_number()over(partion by name ordery time desc) rn
from table t
where t.time <= 你自己的时间)
where rn =1
(
NAME VARCHAR(4),
MyTime DATE,
Money NUMBER(4)
);
INSERT INTO T7 VALUES('a', '17-11月-2011', 1);
INSERT INTO T7 VALUES('a', '18-11月-2011', 2);
INSERT INTO T7 VALUES('a', '16-11月-2011', 5);
INSERT INTO T7 VALUES('a', '13-11月-2011', 7);
INSERT INTO T7 VALUES('b', '11-11月-2011', 10);
INSERT INTO T7 VALUES('b', '20-11月-2011', 9);
INSERT INTO T7 VALUES('c', '16-11月-2011', 5);
INSERT INTO T7 VALUES('c', '14-11月-2011', 3);
测试结果:
在下比较菜
结贴了感谢各位热心人
(select 'a' name, 20111117 time1, 1 money
from dual
union all
select 'a' name, 20111118, 2 money
from dual
union all
select 'a' name, 20111116, 5 money
from dual
union all
select 'a' name, 20111113, 7 money
from dual
union all
select 'b' name, 20111111, 10 money
from dual
union all
select 'b' name, 20111120, 9 money
from dual
union all
select 'c' name, 20111116, 5 money
from dual
union all
select 'c' name, 20111114, 3 money from dual
)
select * from t where t.time1 <= 20111115