USING RANK
I created a simple sql query using rank function as shown below. My question is how do I check the values in the total_income to see if they are different?
Query:
select * from
select cardholderid, appcnum,total_income, Rank() over (PARTITION BY A.APPCNUM
ORDER BY A.EFFENDDATE DESC, A.EFFSTARTDATE DESC, A.CREATEDATE DESC) as Rank
from
TBL_EPIC_BILLSTATUS A
) tmp
where Rank in (2,3)
Results:
CARDHOLDER
APPCNUM
TOTAL_INCOME
RANK
704355
2121362
21912
2
704355
2121362
20938
3
what do you mean by check values in total income?? you have column total column there right??
if i understand it right, you do another rank for total income..
Rank() over (partition by APPCnum order by total_income desc) as [total income rank]
Hope it Helps!!
That wouldn't quite help as even if they were the same value, rank would still give 1 and 2. Dense_rank would give them both 1 if they were the same but wouldn't help identify if they were the same from a dynamic view. You could either do a lead to read the
total_income of the next if that is appropriate or you'd have to pivot them to one row and then compare
Similar Messages
-
How to use "Rank" function in Oracle?
I need to display Top 15 records by using rank function.
Here is my query...I need to pull top 15 FAQ's using the below query.. How can I use RANK function to display the Top 15 FAQ"s in the list.
Select distinct SUb1.FAQ,Sub1.FAQ_Hits,GU.display_Name_FMLS as displayname,ev.ParentLinkrecordid,ev.userid from User GU
Join Event ev
ON LOWER (ev.userid) IN (LOWER (GU.lanid), LOWER (Gu.racfid))
Join (Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID from Event ev
Join SubjectMatter sm
ON (TO_CHAR (sm.smrecordid) = ev.eventdetail1) AND ev.eventdetail1 IS NOT NULL AND sm.smtype = 1
Where (Upper(ev.eventsubtype) in (Upper('FAQ'),Upper('OPENFAQ')))
AND TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= TO_DATE ('20100601', 'yyyymmdd')
and TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= TO_DATE ('20100831', 'yyyymmdd')
Group by sm.stem,ev.Parentlinkrecordid
order by FAQ )sub1
ON Sub1.Topic_ID = ev.ParentLinkrecordid)A few bits that I noticed in the query ...
in (Upper('FAQ'),Upper('OPENFAQ'))1) Do you really a upper for a string which is already in upper case.
Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID2) Do you need a distinct when you are using a GROUP function viz. SUM ?
You rank query is as follows, I am not very good at the ANSI style JOIN so changed it slightly ... :-)
Also notice the usage rank function in the "sub1" query.
select distinct sub1.faq,
sub1.faq_hits,
gu.display_name_fmls as displayname,
ev.parentlinkrecordid,
ev.userid
from user gu, event ev,
(select rank() over (order by sum(ev.eventresults) desc) rnk,
sum(ev.eventresults) as faq_hits,
sm.stem as faq,
ev.parentlinkrecordid as topic_id
from event ev, subjectmatter sm
where (to_char(sm.smrecordid) = ev.eventdetail1)
and ev.eventdetail1 is not null
and sm.smtype = 1
AND upper(ev.eventsubtype) in ('FAQ', 'OPENFAQ')
and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= to_date('20100601', 'yyyymmdd')
and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= to_date('20100831', 'yyyymmdd')
group by sm.stem, ev.parentlinkrecordid
order by faq) sub1
where lower(ev.userid) in (lower(gu.lanid), lower(gu.racfid))
and sub1.topic_id = ev.parentlinkrecordid)
and sub1.rnk <= 15;Like mentioned above, some sample data would have helped. -
How to use to use rank over() function in block coding
Hi,
I am having problem with using rank () over function in block coding. I can't use it in declaration section with select statement.
How to use in executable section of pl sql ?
--Sujanthanks
-
How to use rank() over(...) in a map?
I use rank() over(...) in a Filter operator
validate give a error: ora-30483Currently OWB does not directly support analytical functions. The (not very elegant) workaround could be implementing these feature in custom transformations.
Regards:
Igor -
Sql tuning using rank function
Hi,
Can someone help me in writing the below qry using rank() function?
DELETE FROM stc_calllog_ext a
WHERE a.stc_save_status = 'CT'
AND ROWID IN (SELECT a.ROWID
FROM stc_calllog_ext a, calllog_ext b
WHERE a.prod_line_code= b.prod_line_code
AND a.brand_code = b.brand_code
AND a.model_number = b.model_number
AND a.stc_save_status != b.stc_save_status
AND trunc(a.stc_start_time) = trunc(b.stc_start_time)
AND a.stc_start_time BETWEEN TRUNC(SYSDATE-8) AND TRUNC(SYSDATE)
AND a.call_taker_userid = b.call_taker_userid
AND a.cons_telephone_no =b.cons_telephone_no
)With the information you have provided, I've come up with the following.
SELECT A.ACCOUNT_NO, A.PAYMENT_TYPE, A.INSTALLMENT_TYPE, A.DATE_CHANGE
FROM
(SELECT account_no, payment_type, installment_type, date_change,
LEAD( (payment_type), 1)
over (partition by account_no order by account_no, DATE_CHANGE) LEAD_PAY,
LEAD( (installment_type), 1)
over (partition by account_no order by account_no, DATE_CHANGE) LEAD_INST
from T_ACCNTS ) A
WHERE A.PAYMENT_TYPE <> NVL(A.LEAD_PAY,99)
OR A.INSTALLMENT_TYPE <> NVL(A.LEAD_INST,99)
ORDER BY 1, 4; -
Error using Rank function in Answers
Hi All,
Am trying to generate a report in Answers which lists Top Accounts with Revenue.
I Ranked the Revenue field and it is returning me correct values. ( Rank(account.revenue) )
But, when I try to filter on this field and restrict the rows which shows only top 10 Accounts, it is returning the following error:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1792, message: ORA-01792: maximum number of columns in a table or view is 1000 at OCI call OCIStmtExecute. [nQSError: 17010] SQL statement preparation failed. (HY000)
Can any one help me on this.
Thanks in Advance,
Imtiaz.Hi Joe,
This is the Physical query generated when I use Rank function and the report is fine.
select distinct D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10,
D1.c11 as c11,
D1.c12 as c12,
D1.c13 as c13,
D1.c14 as c14,
D1.c15 as c15
from
(select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10,
D1.c11 as c11,
D1.c12 as c12,
D1.c13 as c13,
D1.c14 as c14,
D1.c15 as c15
from
(select Case when D1.c1 is not null then Rank() OVER ( ORDER BY D1.c1 DESC NULLS LAST ) end as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c1 as c4,
D1.c4 as c5,
D1.c5 as c6,
D1.c6 as c7,
D1.c7 as c8,
D1.c8 as c9,
D1.c9 as c10,
D1.c10 as c11,
D1.c11 as c12,
D1.c12 as c13,
D1.c13 as c14,
D1.c14 as c15,
ROW_NUMBER() OVER (PARTITION BY D1.c1, D1.c2, D1.c3, D1.c4, D1.c5, D1.c6, D1.c7, D1.c8, D1.c9, D1.c10, D1.c11, D1.c12, D1.c13, D1.c14 ORDER BY D1.c1 ASC, D1.c2 ASC, D1.c3 ASC, D1.c4 ASC, D1.c5 ASC, D1.c6 ASC, D1.c7 ASC, D1.c8 ASC, D1.c9 ASC, D1.c10 ASC, D1.c11 ASC, D1.c12 ASC, D1.c13 ASC, D1.c14 ASC) as c16
from
(select distinct T690.SUM_REVN_AMT as c1,
T690.NAME as c2,
T2216.NAME as c3,
T690.X_PETROFAC_REVN as c4,
T690.SUM_WIN_PROB as c5,
T690.X_PERCENT_GET as c6,
T690.SUM_WIN_PROB * T690.X_PERCENT_GET / nullif( 100, 0) as c7,
T690.X_EC_PRIORITY as c8,
T19028.LOGIN as c9,
T690.X_COUNTRY as c10,
T690.X_REGION as c11,
T18311.NAME as c12,
T18641.NAME as c13,
T18238.NAME as c14
from
SIEBEL.S_BU T18238 left outer join (
SIEBEL.S_USER T19028 left outer join (
SIEBEL.S_OPTY T690 left outer join SIEBEL.S_STG T2216 On T690.CURR_STG_ID = T2216.ROW_ID) left outer join SIEBEL.S_ORG_EXT T1189 On T690.PR_DEPT_OU_ID = T1189.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18311 /* Competitor */ On T690.PR_CMPT_OU_ID = T18311.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18641 /* Partner */ On T690.PR_PRTNR_ID = T18641.ROW_ID) left outer join SIEBEL.S_POSTN T19114 On T690.PR_POSTN_ID = T19114.PAR_ROW_ID) left outer join SIEBEL.S_OPTY_BU T18280 On T690.ROW_ID = T18280.OPTY_ID) left outer join SIEBEL.S_OPTY_X T19415 On T690.ROW_ID = T19415.PAR_ROW_ID) On T19028.PAR_ROW_ID = T19114.PR_EMP_ID) On T18238.ROW_ID = T18280.BU_ID
) D1
) D1
where ( D1.c16 = 1 )
) D1
order by c1 desc
But When I apply Filter on this Rank column then it gives me the error. THis is the Physical query for that
select distinct Case when D1.c1 is not null then Rank() OVER ( ORDER BY D1.c1 DESC NULLS LAST ) end as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c1 as c4,
D1.c4 as c5,
D1.c5 as c6,
D1.c6 as c7,
D1.c7 as c8,
D1.c8 as c9,
D1.c9 as c10,
D1.c10 as c11,
D1.c11 as c12,
D1.c12 as c13,
D1.c13 as c14,
D1.c14 as c15
from
(select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10,
D1.c11 as c11,
D1.c12 as c12,
D1.c13 as c13,
D1.c14 as c14
from
(select T690.SUM_REVN_AMT as c1,
T690.NAME as c2,
T2216.NAME as c3,
T690.X_PETROFAC_REVN as c4,
T690.SUM_WIN_PROB as c5,
T690.X_PERCENT_GET as c6,
T690.SUM_WIN_PROB * T690.X_PERCENT_GET / nullif( 100, 0) as c7,
T690.X_EC_PRIORITY as c8,
T19028.LOGIN as c9,
T690.X_COUNTRY as c10,
T690.X_REGION as c11,
T18311.NAME as c12,
T18641.NAME as c13,
T18238.NAME as c14,
Case when T690.SUM_REVN_AMT is not null then Rank() OVER ( ORDER BY T690.SUM_REVN_AMT DESC NULLS LAST ) end as c15
from
SIEBEL.S_BU T18238 left outer join (
SIEBEL.S_USER T19028 left outer join (
SIEBEL.S_OPTY T690 left outer join SIEBEL.S_STG T2216 On T690.CURR_STG_ID = T2216.ROW_ID) left outer join SIEBEL.S_ORG_EXT T1189 On T690.PR_DEPT_OU_ID = T1189.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18311 /* Competitor */ On T690.PR_CMPT_OU_ID = T18311.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18641 /* Partner */ On T690.PR_PRTNR_ID = T18641.ROW_ID) left outer join SIEBEL.S_POSTN T19114 On T690.PR_POSTN_ID = T19114.PAR_ROW_ID) left outer join SIEBEL.S_OPTY_BU T18280 On T690.ROW_ID = T18280.OPTY_ID) left outer join SIEBEL.S_OPTY_X T19415 On T690.ROW_ID = T19415.PAR_ROW_ID) On T19028.PAR_ROW_ID = T19114.PR_EMP_ID) On T18238.ROW_ID = T18280.BU_ID
) D1
where ( D1.c15 <= 10 )
) D1
order by c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15
Thanks,
Imtiaz -
Data read from Memory use - ranked list
Dear Experts,
I am trying to read data from memory use -ranked list.
In general we use function pool to read the data but in case if we should read the data from a class can we do it.
{O:267}-IF_PT_HRS_D_IF~IM_CONTRACT_TES[1]-TES
in the above class in TES table we have data , we have to read data from TES .
In memory use ranked list it is like below
{O:451*\CLASS=CL_PT_HRS_IF}
Object
Regards,
Kartheek.Philip
This one is really tricky. Display value just shows the rank but it would hold the actual value when you try to do calculations.
We have had similar problem but it was not related to ranking.
One Simple approach could be
Make them use Wrokbooks and do this calculation by using a SUM formula in Excel. Excel will consider whta is being displayed as a value for that cell
One far complicated solution is you can use the Olympic ranks and Do your sum in a Macro.
What I mean is if you get the last rank to be 10 then you can write your program to do the sum as
1098765432+1.
This approach could be taken only if they are OK with Olympic ranking.
Edited by: Abhijit N on Dec 10, 2008 10:19 PM -
Using Ranking on MS SQL Server 2005
Hello,
We are on BOXI3.1 base version and have a universe on top of MS SQL Server 2005.
My question is regarding use of rank functions. BO guides state that
You can perform a database ranking only if your database supports
it. If this is not the case, the Add a database ranking button is disabled on
the Query Panel toolbar. Databases that support ranking are Oracle, DB2,
Terradata and Redbrick.
So SQL Server is not in the list. However the add database ranking button is enabled on
my report panel. If i add a ranking the query runs for a long time and times-out.
Is there any universe parameter i need to enable to use ranking? Has any-one mangaged to
use ranking functionality with SQL Server 2005.
Thanks in advance.Hi Bashir Awan,
When we create this Object (using your example) at Universe level is the ranking hardcoded ?
My questions is, say i have Product object (with values A, B, C, D, E), and sales aggregated (10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
Say the table is as follows
Product; sales
A; 10
A; 70*
B; 50
B; 20*
C; 30
C; 60*
D; 40
D; 90
E; 80
E; 100
Note: * represents Oversees sales outside US
Case 1: Now when we rank whole data to select top 3 we should get (E, D, C in Desc order)
Case 2: Now if I apply prompt on Country of sales as US will I get (E, B, D) or is it still (E, D, C as earlier).
Case 3: Similarly if I apply prompt on Product (no prompt on Country) in the filter pane and select (A, D, E) will my results show (E, D, A) or (E, D) as the value of A may be restricted due to ranking formula based on sales at Universe level.
I am sorry I may be asking a very basic question. Thanks
Sudhir. -
How to display total values of revenue after applying top 5 using rank?
Dear Team,
I have a requirement to display sum of all revenues after applying top 5 using rank in Webi.
for Eg:
revenue product
100 aa
200 bb
300 cc
400 dd
500 ee
600 ff
700 gg
If i apply top 5 using rank i will be getting in my output:700, 600,500,400, 300.
But simultaneously i want to get sum of all revenue values (i.e) 2800.
How to achieve this? ur suggestion is much appreciated.
Regards,
BansiHi Bansi,
You can use =nofilter([Revenue])
or sum([Revenue] in report) -
Using ranking and sum to get top 5 products' share of total market
Hi everybody,
I have been playing around with ranking for a while now and I am stuck..
I have a crosstab where I want to show the top 5 products in a specific month. So I have month in my column and products in my rows. I applied a ranking based on revenue only showing the top 5 products. This works like a charm.
Now I would like to sum up the top 5 products' revenue and compare it with the revenue of all products in the market. I have managed to sum the top 5 products' revenue by using the "sum" function in the block, but I have not been able to compare this measure with a total market revenue measure. It seems like because I made the ranking on the top 5 products I cannot create a measure which includes more than these top 5 products and put it in that block.
Is this not something Webi can easily handle??
Thanks in advance!
Best regards,
MortenHi Jaime,
Thank for the suggestion. I forgot to mention that the month column is only showing one month. There is a filter on the month dimension, so that only one month is shown.
I tried using the In Report context, but it gave me wrong results... It seems like it included all months.. I also tried using the noFilter function, but it also gave me wrong results.
Best regards,
Morten -
Top 'n' using rank () function
Hi...
I'm using BO XI 3.0. In my report I need a user to enter TOP 'n' (n=5,10,20,50,100).
For example:
Caller No No of Calls
23467891 10
67698089 35
22377868 17
76378467 10
76374678 20
89978978 6
87786777 11
I already create dimension object for Caller No and measure object for No of Calls in universe.
So I use a rank filter in edit query but it doesn't work.
I also create another measure object in universe name =ranking
rank(No_of_Calls) over(partition by (Caller No) order by (No_of_Calls)).. but it's not work...
So can anybody help me....thanksHi,
Following information might be helpful in resolving the issue.
General Syntax of Ranking :
Rank( measure; (dimensions); [Top|Bottom])
Here is the work flow with an example :- (use efashion universe )
1) Create a webi report selecting objects quarter, year, sales revenue and create a cross tab
2) While creating a cross tab, use the Object Year in columns and object Quarter for rows.
3)Define a variable Var1 = Rank ([Sales Revenue] ; [Quarter]; [Year]) ForEach ([Year])
4) Insert a blank column next to year in the cross tab.
5) Drag and drop the variable Var1 in the new blank column inserted next to Object Year..
You will now find that you have ranking for the years 2001, 2002, 2003 being reflected
independently.
Regards,
Sarbhjeet Kaur -
Prob in using rank in pl/sql ,need logic same of rank function in any way
I have a query as of the following <br>
<br>
SELECT sr_no,cod_acct_no,dat_arrears_due,amt_arrear_due<br>
FROM ( select cod_acct_no,dat_arrears_due,sum(amt_arrears_due) <br>amt_arrear_due,rank() over (partition by cod_acct_no order by <br>dat_arrears_due asc) sr_no<br>
from arrears_table <br>
where amt_arrears_due > 0<br>
and dat_arrears_due <= to_date('31/10/2006','dd/mm/yyyy')<br>
and COD_ARREAR_TYPE = 'C'<br>
group by cod_acct_no,dat_arrears_due<br>
) Z <br>
WHERE z.sr_no <=5 <br>
<br>
I have to use this in a cursor in pl/sql but because i have rank analytic function <br>
I am facing a compilation error ORA-06550: error <br>
<br>
Can you give me a logic which gives same output as of above <br>
<br>
Regards<br>
vamsi krishna<br>
<br>
<br>[1]: (Error): ORA-06550: line 5, column 28: PLS-00103: Encountered the <br>symbol "(" when expecting one of the following: , from <br>
<br>
My oracle version is <br>
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production<br>
PL/SQL Release 8.1.6.0.0 - Production<br>
CORE 8.1.6.0.0 Production<br>
TNS for 32-bit Windows: Version 8.1.6.0.0 - Production<br>
NLSRTL Version 3.4.1.0.0 - Production<br>
<br>I think it is comming for rank function it self <br>
<br> will this version support analytic (rank) function's in pl/sql cursors<br>
Regards<br>
vamsi krishna<br> -
Possible to use ranking value in formula?
Hi!
User wants to compare previous month to current month ranking number to trend the change. Setup is 2 key fig with sales current month and sales previous month where row is sales office. Then calculate single value as rank. Now, I want to use the ranking value in a formula to compare this months rank vs previous months ranking, but it seems not to work as the formula takes the sales value and not the displayed ranking value. Is there a way to do this in bex or is the only way transformation..?
Regards
HenningYou could create a key figure that always displays a fixed value example 1.
You then restrict this individual key figure to payment method C.
The key figure is now only 1 for payment method C.
In your calculation you now say: if key figure = 1 then ... else ...
If statements are not directly possible, you can only do if statemements indirectly by a similar formula:
(key figure = 1) * value
if key figure is one -> result of (key figure = 1) is 1
1 multiplied by value = value
if key figure is not one -> result of (key figure = 1) is 0
0 multiplied by value = 0
You now have an indirect if clause.
Please assign points if this solved your problem,
Best Regards,
Filip -
How to use rank function in obiee rpd using evalute..
i created a logical column:
EVALUATE('RANK() OVER (PARTITION BY %1,%2)' AS DOUBLE PRECISION , Composites.Composites_Fact.MEMBER_LOCKED_BASE_RETURN, Composites.Composites_Fact.COMP_ID)
please provide some solutionThere is a known bug with EVALUATE when returning numbers. When I has the same problem Oracle Metalink has adviced to use CAST on the end result of the EVALUATE and return it as a FLOAT datatype.
CAST(EVALUATE('my_function(%1)', logical_table.ROWID) AS FLOAT) -
How to use RANK function ?
Hello everyone,
here is the query I run in sql developer using RANKFunction.
SELECT Empno, Ename, Job, Mgr, Hiredate, Sal
FROM
(SELECT Empno, Ename, Job, Mgr, Hiredate, Sal,
*RANK*() OVER
(ORDER BY SAL Desc NULLS LAST) AS Emp_Rank
FROM Emp
ORDER BY SAL Desc NULLS LAST)
WHERE Emp_Rank < 6;How I can use this query in my report in obiee or is there any replacement of RANK() function in obiee so that I can use that to get my same above result.
ThanksKuldip wrote:
Thanks, you are absolutely correct. However, By doing this I am getting my output as whic I was not expecting.
Students Marks Rank
student1 95 1
student2 95 1
student3 93 3
student4 93 3
student5 91 5
The output should be as instead
Students Marks Rank
student1 95 1
student2 95 1
student3 93 2
student4 93 2
student5 91 3
Can It be done like this ?
Thanks.
Edited by: Kuldip on Mar 15, 2012 11:51 PMHi Boss,
I think you copied the above scenario from this site..
http://oracle-bi.siebelunleashed.com/articles/rank-and-dense-rank-functionsobiee/
Then why asking how to do this? Are you testing us? Doesn't that site say how to achieve this?
Maybe you are looking for
-
How do I restore all bookmarks from an external hard drive to a refreshed firefox?
I just "refreshed" Firefox and lost ALL of my passwords, even though the instructions said they would be saved. I have tried copying them from the Old Firefox Data folder and this does NOTHING. I have all of the data I need on an external hard drive
-
I updated Firefox and now it will not open at all. The hourglass shows that it's working but then nothing. I went to add/remove and removed mozilla and reinstalled it and still the same thing. It worked fine before I updated. Now I can't even remove
-
Camera not working :(
I went swimming with the Xepria Z1 compact 2 days ago and took some underwater videos. I came out and phone seemed to work perfectly. I went for a shower and came back and my phone was extemely hot and wasnt swithcing on. It finally switched on after
-
Apple tv not really connecting
I just got an apple tv, and set it up. As I entered my internet password I didnt get a five digit code, though it says on apples info that one should pop up, so I couldnt put that code into itunes. Itunes on my pc seems to only occationally recognise
-
Audit Files Not Updating in Essbase
Hi Experts, Audit files are not updating.( alg and .atx). The two audit files were updating previously but for the last two months they are not updating. Please suggest me.