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

Re: Ranking in Crystal reports

$
0
0

hi Yogi,

 

i've attached a sample report that i built using a different subreport method than the one Sastry mentioned. this is the RankingWithSubreport file. please extract the contents and change the .txt extension to .rpt. the report doesn't have instructions on it. it uses a set of arrays which are passed from the subreports to the main report.

 

if you've got a database that has window functions like rank then you may wish to look into create a command and base your report off of that. here's some sample syntax below that ranks suppliers by count of orders. note that this is in sap hana syntax so your database syntax may vary. the advantage of doing this in sql is the amount of work is less and it's easy to add in more ranks if you wish.

 

WITH

DT AS

(

SELECT DISTINCT "FCTSUPPLIERORDERS"."SUPPLIERID",  COUNT("FCTSUPPLIERORDERS"."SUPPLIERORDERID") AS COUNT

FROM   "STS"."FCTSUPPLIERORDERS" "FCTSUPPLIERORDERS"

GROUP BY "FCTSUPPLIERORDERS"."SUPPLIERID"

ORDER BY "FCTSUPPLIERORDERS"."SUPPLIERID"

),

RDT AS

(

SELECT

SUPPLIERID,

RANK() OVER (ORDER BY COUNT DESC) AS RANK

FROM DT

)

 

 

SELECT *

FROM DT, RDT

WHERE DT.SUPPLIERID = RDT.SUPPLIERID

ORDER BY DT.SUPPLIERID

 

which gives these results

 

Untitled.jpg

i've also attached this report based on the derived tables.

 

i hope this helps,

jamie


Viewing all articles
Browse latest Browse all 10671

Trending Articles



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