求一sql

haibozhang 2005-07-27 01:23:43
create table BANDWIDTHPOWER
(
DATETIME date not null,
DESCONTENT NUMBER(10),
FVALUE NUMBER(10) not null,
TS0AVGDISTURBPOW NUMBER(10),
TS0AVGBANDWIDTHPOW NUMBER(10)
}

现在需要求在一个时间段内,TS0AVGDISTURBPOW和TS0AVGBANDWIDTHPOW的最大值,
并求此段时间内,最近的那个时间的DESCONTENT值?如何写sql?
...全文
116 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
henghowzc 2005-07-28
  • 打赏
  • 举报
回复
顶上楼
沝林 2005-07-27
  • 打赏
  • 举报
回复
上面是最小的日期的DESCONTENT,改正下:

select distinct max(TS0AVGDISTURBPOW) over(),
max(TS0AVGBANDWIDTHPOW) over(),
first_value(DESCONTENT) over(order by DATETIME desc)
from BANDWIDTHPOWER
where DATETIME between ...and ...
沝林 2005-07-27
  • 打赏
  • 举报
回复
select distinct max(TS0AVGDISTURBPOW) over(),
max(TS0AVGBANDWIDTHPOW) over(),
first_value(DESCONTENT) over(order by DATETIME)
from BANDWIDTHPOWER
where DATETIME between ...and ...
waterfirer 2005-07-27
  • 打赏
  • 举报
回复
SQL> select max(b),max(c),max(a) from
2 (select datetime,b,c,
3 (select a from test where datetime=
4 (select max(datetime) from test where
5 datetime between sysdate-5 and sysdate-2)) a
6 from test) table1
7 where table1.datetime between sysdate-5 and sysdate;

MAX(B) MAX(C) MAX(A)
---------- ---------- ----------
20 52 2

SQL> select * from test;

DATETIME A B C
---------- ---------- ---------- ----------
26-7月 -05 1 1 1
25-7月 -05 2 2 2
24-7月 -05 5 20 2
23-7月 -05 3 10 52
22-7月 -05 7 6 8

SQL>
henghowzc 2005-07-27
  • 打赏
  • 举报
回复
select descontent
from BANDWIDTHPOWER where datetime=( select max(Datetime) from bandwidthpower
where datetime between d1 and d2 =×

select max(TS0AVGDISTURBPOW),max(TS0AVGBANDWIDTHPOW),(×)
from BANDWIDTHPOWER
where Datetime between d1 and d2;

有这样套用的啊?晕死,根本不可以的
henghowzc 2005-07-27
  • 打赏
  • 举报
回复
上面的大哥牛啊,这个可以运行吗?你用的是oracle吗?
我怎么不行啊,怀疑中....
你写的根本不行啊。我倒
waterfirer 2005-07-27
  • 打赏
  • 举报
回复
select max(TS0AVGDISTURBPOW),max(TS0AVGBANDWIDTHPOW),(select descontent
from BANDWIDTHPOWER where datetime=( select max(Datetime) from bandwidthpower
where datetime between d1 and d2))
from BANDWIDTHPOWER
where Datetime between d1 and d2;
haibozhang 2005-07-27
  • 打赏
  • 举报
回复
能不能在一个sql里面搞定?
complayer 2005-07-27
  • 打赏
  • 举报
回复
可以分两步做:
select max(TS0AVGDISTURBPOW),max(TS0AVGBANDWIDTHPOW) from BANDWIDTHPOWER
where Datetime between d1 and d2;

select descontent from BANDWIDTHPOWER
where datetime=( select max(Datetime) from bandwidthpower
where datetime between d1 and d2);

17,088

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧