如何列出规范数据

np8igboo  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(222)

我写了一个观点。您可以在代码下看到的视图示例。我正在为列表数据编写脚本。视图示例:

DONEM_ID, URUN_ID, TARIFF, TARIFE_PRI, START_DATE, END_DATE
xx10      1         12      123        01-02-2003  null
xx11      1         12      123        01-02-2003  01-11-2003
xx12      1         12      124        01-11-2003  null

我要列出

URUN_ID, TARIFF, TARIFE_PRI, START_DATE, END_DATE
1         12      123        01-02-2003  01-11-2003
1         12      124        01-11-2003  null

我如何列出这个?

lqfhib0f

lqfhib0f1#

聚合通常有帮助(您可能需要的代码从第8行开始):

SQL> alter session set nls_date_format = 'mm-dd-yyyy';

Session altered.

SQL> with
  2  -- sample data; you have that, don't type it
  3  test (donem_id, urun_id, tariff, tarife_pri, start_date, end_date) as
  4    (select 'xx10', 1, 12, 123, date '2003-01-02', null              from dual union all
  5     select 'xx11', 1, 12, 123, date '2003-01-02', date '2003-01-11' from dual union all
  6     select 'xx12', 1, 12, 124, date '2003-01-11', null              from dual
  7    )
  8  select urun_id, tariff, tarife_pri, min(start_date) start_date, max(end_date) end_date
  9  from test
 10  group by urun_id, tariff, tarife_pri
 11  order by urun_id, tariff, tarife_pri;

   URUN_ID     TARIFF TARIFE_PRI START_DATE END_DATE
---------- ---------- ---------- ---------- ----------
         1         12        123 01-02-2003 01-11-2003
         1         12        124 01-11-2003

SQL>

相关问题