Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 10498

Re: Top N with exclusion but add back exclusion to results (or Union query)

$
0
0

hi Chris,

 

when you create a new report, you'll see the Add Command option to create a report based off of a command object as Dell mentioned.

 

assuming that you've got a verison of oracle that supports the select with directive, you can use a command similar to what's below, but changing the field names to your own...

 

WITH  DRT AS (SELECT DS.COMPANYNAME AS NAME, SUM(FSO.QUANTITYORDERED) AS AMOUNT

                            FROM STS.DIMSUPPLIER DS INNER JOIN STS.FCTSUPPLIERORDERS FSO ON DS.SUPPLIERID=FSO.SUPPLIERID

                            GROUP BY DS.COMPANYNAME ),

           DRTR AS (SELECT DRT.*, RANK() OVER (ORDER BY AMOUNT DESC) as RANK  FROM DRT)

 

SELECT 'TOP 5' AS GROUPER, DRTR.* FROM DRTR WHERE RANK <= 5 AND NAME <> 'ÚNKNOWN'

UNION

SELECT 'UNKOWN' AS GROUPER, DRTR.* FROM DRTR WHERE NAME = 'ÚNKNOWN'

UNION

SELECT 'OTHERS NOT IN TOP 5' AS GROUPER, DRTR.* FROM DRTR WHERE RANK > 5 AND NAME <> 'ÚNKNOWN'

 

 

cheers,

-jamie


Viewing all articles
Browse latest Browse all 10498

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>