我必须将表转换为另一个表。我有这些行:
<ul class="edit-list">
<li>
<i class="icon"></i>
<div class="frame">
<img>
</div>
</li>
<li>
<i class="icon"></i>
<div class="frame">
<img>
</div>
</li>
<li>
<i class="icon"></i>
<div class="frame">
<img>
</div>
</li>
</ul>
问题是日期不是连续的,最近可以重复数量。所需的输出如下:
quantity fdate
3 2006.10.11.
6 2006.10.18.
6 2006.10.19.
6 2006.10.23.
4 2006.10.25.
6 2006.10.28.
6 2006.10.30.
看起来很简单,但是分组,分钟,最大值,等级都无法帮助我,我无法找到诀窍。我怎样才能做到这一点?谢谢你提前。
答案 0 :(得分:0)
希望这会有所帮助:
SQL>
SQL> WITH table_(quantity , fdate) AS
2 (select 3, to_date('2006.10.11.', 'yyyy.mm.dd.') from dual union all
3 select 6, to_date('2006.10.18.', 'yyyy.mm.dd.') from dual union all
4 select 6, to_date('2006.10.19.', 'yyyy.mm.dd.') from dual union all
5 select 6, to_date('2006.10.23.', 'yyyy.mm.dd.') from dual union all
6 select 4, to_date('2006.10.25.', 'yyyy.mm.dd.') from dual union all
7 select 6, to_date('2006.10.28.', 'yyyy.mm.dd.') from dual union all
8 select 6, to_date('2006.10.30.', 'yyyy.mm.dd.') from dual),
9 -------
10 -- End of data preparation
11 -------
12 table2 AS ( select quantity ,
13 fdate,
14 row_number() OVER (ORDER BY fdate) -
15 row_number() OVER (PARTITION BY quantity ORDER BY fdate) AS grp
16 FROM table_)
17 SELECT quantity, to_char(MIN(fdate), 'yyyy.mm.dd.') START_DT, to_char(MAX(fdate), 'yyyy.mm.dd.') END_DT
18 FROM table2
19 GROUP BY quantity, grp
20 ORDER BY 2
21 /
QUANTITY START_DT END_DT
---------- ----------- -----------
3 2006.10.11. 2006.10.11.
6 2006.10.18. 2006.10.23.
4 2006.10.25. 2006.10.25.
6 2006.10.28. 2006.10.30.
SQL>