早教吧作业答案频道 -->其他-->
用oracle的话,查询语句该怎么写?表中相关的字段有,beginDate,endDate,interest_rate三个,起始时间至结束时间这一时间段内,对应一个值,前两个字段是char(8)型的,对应日期的八个数字'yyyymmdd' 如:id begin
题目详情
用oracle的话,查询语句该怎么写?
表中相关的字段有,beginDate,endDate,interest_rate三个,
起始时间至结束时间这一时间段内,对应一个值,前两个字段是char(8)型的,
对应日期的八个数字'yyyymmdd' 如:
id begin_date end_date interest_rate
----------- ---------- -------- ---------------------------------------
1 20130101 20130104 5.00000000
2 20130105 20130110 3.00000000
3 20130111 20130113 6.00000000
4 20130114 20130120 2.00000000
5 20130121 20130128 9.00000000
6 20130129 20130220 4.00000000
假设给定一个起始日期和结束日期,我需要查询这之间对应的每一天的interest_rate,
比如查询20130103到20130115,每天对应的值,查询结果如:
date_01 INTEREST_RATE
--------------------------------- -----------------------------
2013-01-03 00:00:00.000 5.00000000
2013-01-04 00:00:00.000 5.00000000
2013-01-05 00:00:00.000 3.00000000
2013-01-06 00:00:00.000 3.00000000
2013-01-07 00:00:00.000 3.00000000
2013-01-08 00:00:00.000 3.00000000
2013-01-09 00:00:00.000 3.00000000
2013-01-10 00:00:00.000 3.00000000
2013-01-11 00:00:00.000 6.00000000
2013-01-12 00:00:00.000 6.00000000
2013-01-13 00:00:00.000 6.00000000
2013-01-14 00:00:00.000 2.00000000
2013-01-15 00:00:00.000 2.00000000
Oracle 应该怎么写查询语句,
表中相关的字段有,beginDate,endDate,interest_rate三个,
起始时间至结束时间这一时间段内,对应一个值,前两个字段是char(8)型的,
对应日期的八个数字'yyyymmdd' 如:
id begin_date end_date interest_rate
----------- ---------- -------- ---------------------------------------
1 20130101 20130104 5.00000000
2 20130105 20130110 3.00000000
3 20130111 20130113 6.00000000
4 20130114 20130120 2.00000000
5 20130121 20130128 9.00000000
6 20130129 20130220 4.00000000
假设给定一个起始日期和结束日期,我需要查询这之间对应的每一天的interest_rate,
比如查询20130103到20130115,每天对应的值,查询结果如:
date_01 INTEREST_RATE
--------------------------------- -----------------------------
2013-01-03 00:00:00.000 5.00000000
2013-01-04 00:00:00.000 5.00000000
2013-01-05 00:00:00.000 3.00000000
2013-01-06 00:00:00.000 3.00000000
2013-01-07 00:00:00.000 3.00000000
2013-01-08 00:00:00.000 3.00000000
2013-01-09 00:00:00.000 3.00000000
2013-01-10 00:00:00.000 3.00000000
2013-01-11 00:00:00.000 6.00000000
2013-01-12 00:00:00.000 6.00000000
2013-01-13 00:00:00.000 6.00000000
2013-01-14 00:00:00.000 2.00000000
2013-01-15 00:00:00.000 2.00000000
Oracle 应该怎么写查询语句,
▼优质解答
答案和解析
创建测试表
create table test
(id int,
begin_date char(8),
end_date char(8),
interest_rate int);
insert into test values (1,'20130101','20130104',5);
insert into test values (2,'20130105','20130110',3);
insert into test values (3,'20130111','20130113',6);
insert into test values (4,'20130114','20130120',2);
执行
with t as
(select to_char(to_date('20130103','yyyymmdd')+rownum-1,'yyyymmdd') as tdate from dual connect by rownum<50)
select t.tdate,test.interest_rate from t,test
where t.tdate between '20130103' and '20130115' and t.tdate between test.begin_date and test.end_date
结果
create table test
(id int,
begin_date char(8),
end_date char(8),
interest_rate int);
insert into test values (1,'20130101','20130104',5);
insert into test values (2,'20130105','20130110',3);
insert into test values (3,'20130111','20130113',6);
insert into test values (4,'20130114','20130120',2);
执行
with t as
(select to_char(to_date('20130103','yyyymmdd')+rownum-1,'yyyymmdd') as tdate from dual connect by rownum<50)
select t.tdate,test.interest_rate from t,test
where t.tdate between '20130103' and '20130115' and t.tdate between test.begin_date and test.end_date
结果

看了 用oracle的话,查询语句...的网友还看了以下:
输入阻抗等于输出阻抗时候负载获得最大功率是怎么通过公式推导出来的?P=I^2*R=E^2*R/(R 2020-05-13 …
连字成词(英语)l u o e b s r u s r e t o s w a e s r t e 2020-05-14 …
关于量子力学的用角动量量子化J=n*(hbar)推rn和En的过程中:圆轨道给出mv^2/r=e^ 2020-05-15 …
用这些英文字母拼词这些英文字母打乱了顺序.一个题目一个词.第一题:r,c,t,a,e,s,r第二题 2020-05-16 …
纵横字谜之英语暑假作业题(s)(o)(r)(r)(n)(g)(r)(e))(a)(k)(k)(e) 2020-06-06 …
E^2*R/(R+r)^2=E^2/(R-r)^2/R+4r(某公式推导最后两行)本人只得:=E^ 2020-06-07 …
英语单词填空1.时间状语:d-r-n-2.场所:b-s-s-o-f-r--e-a-t-e-t3.教 2020-07-14 …
对的打对错的打错gowithuslikecollectdollsturntoleftonfootgo 2020-11-01 …
(e)(a)(r)thush(e)(r)sh(i)(r)tl(e)(a)(r)ncol(o)(u)( 2020-11-27 …
已知电源电压为E,内阻为y,输出功率与负载电阻R的导数关系式P'(R)=[E∧2*R/(R+r)∧2 2020-12-18 …