2017-05-16 2 views
0

ある種の入札方法を含むすべてのカード取引について報告しようとしています。XMLSEQUENCE - 子が "void"を含む場合、親を無視する

「登録番号」、「トランザクション数」、「合計値」という3つの列のレポート。

私が持っている問題は、トランザクションに複数の "TokenisedCardTenderItem"が含まれている可能性があります。以下のクエリでは、これらとカウントと合計が正しく取得されます。しかしながら...

"TokenisedCardTenderItem"は、特定の入札が取り消された何らかの理由で、 "VoidValue"という意味の子供を含むことができます。以下のクエリでは、これらの値を数え加えています。

私の質問は、 "VoidValue"という子を持つが、そうでない "TokenisedCardTenderItem"を数え続けているすべての "TokenisedCardTenderItem"を除外する方法です。私が見て望んでいるだろう。このことから

  <POSBasket> 
       <TokenisedCardTenderItem> 
        <LineNumber>3</LineNumber> 
        <NetValue>-1</NetValue> 
        <VoidValue>1</VoidValue> 
        <EffectiveNetValue>-1</EffectiveNetValue> 
       </TokenisedCardTenderItem> 
       <VoidItem> 
        <LineNumber>4</LineNumber> 
        <NetValue>1</NetValue> 
        <EffectiveNetValue>1</EffectiveNetValue> 
        <VoidedLineNumber>3</VoidedLineNumber> 
       </VoidItem> 
       <TokenisedCardTenderItem> 
        <LineNumber>5</LineNumber> 
        <NetValue>2</NetValue> 
        <EffectiveNetValue>2</EffectiveNetValue> 
        <PreformattedTextLines> 
         <PreformattedTextVoucherType>1</PreformattedTextVoucherType> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine>CONTACTLESS</PreformattedTextLine> 
         <PreformattedTextLine>SALE</PreformattedTextLine> 
         <PreformattedTextLine>TOTAL: GBP0.02</PreformattedTextLine> 
        </PreformattedTextLines> 
       </TokenisedCardTenderItem> 
       <TokenisedCardTenderItem> 
        <LineNumber>6</LineNumber> 
        <NetValue>3</NetValue> 
        <EffectiveNetValue>3</EffectiveNetValue> 
        <PreformattedTextLines> 
         <PreformattedTextVoucherType>1</PreformattedTextVoucherType> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine></PreformattedTextLine> 
         <PreformattedTextLine>CONTACTLESS</PreformattedTextLine> 
         <PreformattedTextLine>SALE</PreformattedTextLine> 
         <PreformattedTextLine>TOTAL: GBP0.03</PreformattedTextLine> 
        </PreformattedTextLines> 
       </TokenisedCardTenderItem> 
      </POSBasket> 

SELECT 
terminal_number 
,count (Extractvalue(c.column_value, 'TokenisedCardTenderItem/PreformattedTextLines/PreformattedTextLine[7]')) as con 
,count (Extractvalue(c.column_value, 'TokenisedCardTenderItem/NetValue'))/100 as val 
FROM baskets b , 
TABLE(xmlsequence(extract(xmltype(b.xml),'/POSBasket/TokenisedCardTenderItem'))) c 
where DATE_CREATED>TO_DATE('2017-05-12 00:00:00','yyyy-MM-dd HH24:mi:ss') 
AND store_id = 9999 
AND terminal_number = 982 
and EXISTSNODE(xmltype.createxml(xml), '/POSBasket/TokenisedCardTenderItem/PreformattedTextLines[PreformattedTextLine="CONTACTLESS"]') = 1 
GROUP BY terminal_number, 
     Extractvalue(c.column_value, 'PreformattedTextLines/PreformattedTextLine[7]') 
order by 1,2 

は、以下のXMLのバージョンをダウンカット

Terminal Con Val 
    982  2  0.05 

しかし、ボイドnetvalueが含まれているように私は以下を得ます。

Terminal Con Val 
    982  2  0.06 
+1

探しているものだと思います。 – MT0

答えて

0

私は[MCVE]いくつかのサンプルデータとあなたの予想出力などを提供してください、これはあなたが

SQL> with MY_TABLE as 
    2 (
    3 select 982 as TERMINAL, XMLTYPE(
    4 '   <POSBasket> 
    5     <TokenisedCardTenderItem> 
    6      <LineNumber>3</LineNumber> 
    7      <NetValue>-1</NetValue> 
    8      <VoidValue>1</VoidValue> 
    9      <EffectiveNetValue>-1</EffectiveNetValue> 
    10     </TokenisedCardTenderItem> 
    11     <VoidItem> 
    12      <LineNumber>4</LineNumber> 
    13      <NetValue>1</NetValue> 
    14      <EffectiveNetValue>1</EffectiveNetValue> 
    15      <VoidedLineNumber>3</VoidedLineNumber> 
    16     </VoidItem> 
    17     <TokenisedCardTenderItem> 
    18      <LineNumber>5</LineNumber> 
    19      <NetValue>2</NetValue> 
    20      <EffectiveNetValue>2</EffectiveNetValue> 
    21      <PreformattedTextLines> 
    22       <PreformattedTextVoucherType>1</PreformattedTextVoucherType> 
    23       <PreformattedTextLine></PreformattedTextLine> 
    24       <PreformattedTextLine></PreformattedTextLine> 
    25       <PreformattedTextLine></PreformattedTextLine> 
    26       <PreformattedTextLine></PreformattedTextLine> 
    27       <PreformattedTextLine></PreformattedTextLine> 
    28       <PreformattedTextLine></PreformattedTextLine> 
    29       <PreformattedTextLine>CONTACTLESS</PreformattedTextLine> 
    30       <PreformattedTextLine>SALE</PreformattedTextLine> 
    31       <PreformattedTextLine>TOTAL: GBP0.02</PreformattedTextLine> 
    32      </PreformattedTextLines> 
    33     </TokenisedCardTenderItem> 
    34     <TokenisedCardTenderItem> 
    35      <LineNumber>6</LineNumber> 
    36      <NetValue>3</NetValue> 
    37      <EffectiveNetValue>3</EffectiveNetValue> 
    38      <PreformattedTextLines> 
    39       <PreformattedTextVoucherType>1</PreformattedTextVoucherType> 
    40       <PreformattedTextLine></PreformattedTextLine> 
    41       <PreformattedTextLine></PreformattedTextLine> 
    42       <PreformattedTextLine></PreformattedTextLine> 
    43       <PreformattedTextLine></PreformattedTextLine> 
    44       <PreformattedTextLine></PreformattedTextLine> 
    45       <PreformattedTextLine></PreformattedTextLine> 
    46       <PreformattedTextLine>CONTACTLESS</PreformattedTextLine> 
    47       <PreformattedTextLine>SALE</PreformattedTextLine> 
    48       <PreformattedTextLine>TOTAL: GBP0.03</PreformattedTextLine> 
    49      </PreformattedTextLines> 
    50     </TokenisedCardTenderItem> 
    51    </POSBasket>') as XML_DOC 
    52 from DUAL 
    53 ) 
    54 select TERMINAL, CNT, SUM(VAL)/100 
    55 from MY_TABLE, 
    56   XMLTABLE(
    57   '/POSBasket' 
    58   passing XML_DOC 
    59   columns 
    60    CNT NUMBER(2) PATH 'count(/POSBasket/TokenisedCardTenderItem/PreformattedTextLines/PreformattedTextLine[ 
7])', 
    61    TCTI_XML XMLTYPE PATH '/POSBasket/TokenisedCardTenderItem[not(VoidValue)]' 
    62  ), 
    63   XMLTABLE(
    64   'TokenisedCardTenderItem' 
    65   passing TCTI_XML 
    66   COLUMNS 
    67   VAL NUMBER(2) PATH 'NetValue' 
    68  ) 
    69 group by TERMINAL, CNT 
    70/

    TERMINAL  CNT SUM(VAL)/100 
---------- ---------- ------------ 
     982   2   .05 

SQL> 
SQL> 
SQL> 
関連する問題