plsql只显示1个日期,查看

时间:2017-03-31 09:31:42

标签: sql oracle view

在我的视图中,描述字段中填充了一个日期字段,但是相同的日期字段有七次但是具有不同的order_keys(这就是它应该如何)。如何使视图仅显示其中一个日期字段?

    CREATE OR REPLACE FORCE VIEW CCI.VW_TA04_BAG_5B
(
   ID,
   LIST_DESCRIPTION,
   ORDER_KEY
)
AS
   SELECT 
          distinct LPAD (bac.bag_id, 4, '0') || LPAD (bac.ID, 4, '0'),
          '      ' || bar.SCORE_RULE_VALID_TO,
          LPAD (bac.order_key, 4, '0')  || LPAD (bar.order_key, 4, '0')
     FROM BART_CATEGORIES bac,
          BART_CATEGORIES_LAE bacl,
          BART_CATEGORY_rules bar
    WHERE     bacl.lae_id = pkg_process.language
          AND (bar.BAC_ID = bac.id)
          AND Bacl.BAC_ID = bac.id
          AND bar.SCORE_RULE_VALID_TO IS NOT NULL
    order by 3

输出如下:

ID                Description order key
00010001          20-MAR-17 00020168
00010001          20-MAR-17 00020169
00010001          20-MAR-17 00020170
00010001          20-MAR-17 00020171
00010001          20-MAR-17 00020172
00010001          20-MAR-17 00020173
00010001          20-MAR-17 00020174
00010001          08-MAR-17 00020175
00010001          08-MAR-17 00020176
00010001          08-MAR-17 00020177
00010001          08-MAR-17 00020178
00010001          08-MAR-17 00020179

1 个答案:

答案 0 :(得分:0)

如果你每个id和list_description后面有一行,这是你可以做到的一种方式:

CREATE OR REPLACE FORCE VIEW CCI.VW_TA04_BAG_5B
  (ID,
   LIST_DESCRIPTION,
   ORDER_KEY)
AS
SELECT ID,
       list_desciption,
       MAX(order_key) order_key
FROM   (SELECT lpad(bac.bag_id, 4, '0') || lpad(bac.id, 4, '0') id,
               '      ' || bar.score_rule_valid_to list_description,
               lpad(bac.order_key, 4, '0') || lpad(bar.order_key, 4, '0') order_key
        FROM   bart_categories bac, bart_categories_lae bacl, bart_category_rules bar
        WHERE  bacl.lae_id = pkg_process.language
        AND    (bar.bac_id = bac.id)
        AND    bacl.bac_id = bac.id
        AND    bar.score_rule_valid_to IS NOT NULL)
GROUP BY ID,
         list_description
ORDER BY order_key;