Frage

All,

I am trying to pair two or more records in a grandparent table so that I can then find its grand children records using one grandchild to start from.

So the structure is like so

  • S_ASSET x 1 record
  • S_ASSET_X x 2 child records
  • CX_ASSET_XM x 1 grand child records

Therefore the cardinality is one Grandparent can have 2 Grandchild records

This CX_ASSET_XM table will hold information about TCP/IP calls of a Grandchild asset. These calls are not synchronized. therefore one Grandchild asset may make a call today but the other one has not made a call since yesterday.

In my query I find all the grand children records that have been created today (sysdate) and then traverse up the relationship to find the Grandparent, then I traverse back down to find the other twin in the Grandchildren tuple.

The problem with my query is that it returns every single TCP/IP call a pair has made but I only want the most recent callback of each grandchild to analyse

Here is an illustration

enter image description here

So to minimize my result set I am trying to use a ROW_NUM function to get only the results I need which is the most recent callback date for each grand child record.

Query

SELECT cb.ssid, cb.created_by, cb.callback_date, cb.callback_num,
       asset.desc_text, asset.prom_integ_id, asset.integration_id
       --Traversing Up to find the Grandparent record of
FROM   SIEBEL.CX_ASSET_XM cb
       JOIN SIEBEL.S_ASSET_X assetx ON cb.SSID = assetx.attrib_37
       JOIN SIEBEL.S_ASSET asset ON assetx.par_row_id = asset.row_id
WHERE  asset.prom_integ_id IN
--Traversing Down to find the other pair
(   SELECT asset.prom_integ_id,
           ROW_NUMBER() OVER (PARTITION BY cb.ssid
                                  ORDER BY cb.callback_date DESC)
    FROM   SIEBEL.CX_ASSET_XM cb
           JOIN SIEBEL.S_ASSET_X assetx ON cb.ssid = assetx.attrib_37
           JOIN SIEBEL.S_ASSET asset ON assetx.par_row_id = asset.row_id
);

Error

ORA-00913: too many values
00913. 00000 -  "too many values"
*Cause:    
*Action:
Error at Line: 7 Column: 36

Am I using the ROW_NUM and PARTITION correctly in this query structure?

Thanks

ORACLE DB Version is 10g Enterprise Edition Release 10.2.0.3.0 - 64bit

War es hilfreich?

Lösung

The problem is that you use IN operator which, in this case, expects one set of values to work on, but the subquery returns two columns, not one:

WHERE asset.prom_integ_id IN
--Traversing Down to find the other pair
(   SELECT asset.prom_integ_id, ROW_NUMBER() OVER (PARTITION BY cb.ssid ORDER BY cb.callback_date DESC)

Should be:

WHERE asset.prom_integ_id IN
--Traversing Down to find the other pair
(   SELECT asset.prom_integ_id

And, starting with that, I guess that the value returned from ROW_NUMBER should be accessed earlier, so it would look like this:

SELECT cb.ssid, cb.created_by, cb.callback_date, cb.callback_num, asset.desc_text, asset.prom_integ_id, asset.integration_id
--Traversing Up to find the Grandparent record of
FROM SIEBEL.CX_ASSET_XM cb
    JOIN SIEBEL.S_ASSET_X assetx
      ON cb.SSID = assetx.attrib_37
    JOIN SIEBEL.S_ASSET asset
      ON assetx.par_row_id = asset.row_id
WHERE asset.prom_integ_id IN
--Traversing Down to find the other pair
(   SELECT prom_integ_id
    FROM (
SELECT asset.prom_integ_id, ROW_NUMBER() OVER (PARTITION BY cb.ssid ORDER BY cb.callback_date DESC) row_n
    FROM SIEBEL.CX_ASSET_XM cb
    JOIN SIEBEL.S_ASSET_X assetx
      ON cb.ssid = assetx.attrib_37
    JOIN SIEBEL.S_ASSET asset
      ON assetx.par_row_id = asset.row_id
) where row_n = 1
);

I'm not sure it is what you wanted - can you check it?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top