oracle避免同一sql多次查询,Oracle SQL - 在一个查询中生成一行答案的最简单方法,因此我不必多次运行查询?...
不確定我是否理解正確,但這可能是你想要的。但可能性能欠佳。
12:32:22 HR@vm_xe> l
1 with player(id, dt) as (
2 select 1, date '2012-01-01' from dual union all
3 select 2, date '2012-01-01' from dual union all
4 select 3, date '2012-01-02' from dual union all
5 select 4, date '2012-01-03' from dual union all
6 select 5, date '2012-01-04' from dual union all
7 select 6, date '2012-01-05' from dual union all
8 select 7, date '2012-01-06' from dual union all
9 select 8, date '2012-01-07' from dual union all
10 select 9, date '2012-01-08' from dual union all
11 select 10, date '2012-01-09' from dual union all
12 select 11, date '2012-01-10' from dual
13 )
14 select distinct
15 to_char(dt, 'dd-mm-yyyy') dt
16 ,count(*) over (order by trunc(dt) range interval '7' day preceding) week_cnt
17 from player
18* order by 1, 2
12:32:22 HR@vm_xe> /
DT WEEK_CNT
---------- ----------
01-01-2012 2
02-01-2012 3
03-01-2012 4
04-01-2012 5
05-01-2012 6
06-01-2012 7
07-01-2012 8
08-01-2012 9
09-01-2012 8
10-01-2012 8
10 rows selected.
Elapsed: 00:00:00.01附:不要像代碼那樣
(To_Date('2012-sep-03','yyyy-mon-dd')-Trunc(Init_Dtime))<=7代碼就像
init_time between to_date('2012-SEP-03', 'yyyy-mon-dd') and to_date('2012-SEP-03', 'yyyy-mon-dd') + 7除非你不關(guān)心索引,當(dāng)然:)
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的oracle避免同一sql多次查询,Oracle SQL - 在一个查询中生成一行答案的最简单方法,因此我不必多次运行查询?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【小松教你手游开发】【unity实用技能
- 下一篇: oracle 赋值到cmd,CMD操作o