Rank function in sql
Hi All,
May I know the options oracle provides to know the first non null value in a group
Thanks in advance
first_value(c1 ignore nulls) over(partition by c2 order by c3)FIRST_VALUE<a/>
first_value(c1 ignore nulls) over(partition by c2 order by c3)
Similar Messages
-
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. -
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> -
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; -
제품 : PL/SQL
작성날짜 : 2001-09-11
RANK FUNCTION IN ORACLE 8I
==========================
EXPLANATION
oracle 8i(8.1.6) 부터 가능한 rank function 입니다.
8.1.5 에서는 ora-923 error 가 납니다.
plsql 내에서는 oracle 9i 부터 가능합니다.
8.1.6에서는 ora-900 error가 납니다.
EXAMPLE
<RANK() OVER ( query_partition_clause ORDER_BY clause) >
- 중복 rank 값만큼 다음 순위는 생략
SQL>SELECT deptno, ename, sal, comm,
RANK() OVER (PARTITION BY deptno ORDER BY sal DESC, comm) as rk
FROM emp;
DEPTNO ENAME SAL RK
10 KING 5000 1
10 CLARK 2450 2
10 MILLER 1300 3
20 3500 1
20 SCOTT 3000 2
20 FORD 3000 2
20 JONES 2975 4
20 ADAMS 1100 5
20 SMITH 800 6
30 BLAKE 2850 1
30 ALLEN 1600 2
30 TURNER 1500 3
30 WARD 1250 4
30 MARTIN 1250 5
40 JAMES 777 1
9 1
<DENSE_RANK( ) OVER ( query_partition_clause ORDER_BY clause ) >
- 중복 rank 의 수와 무관하게 numbering
SQL>SELECT dname, ename, sal, DENSE_RANK()
OVER (PARTITION BY dname ORDER BY sal) as drank
FROM emp, dept
WHERE emp.deptno = dept.deptno
AND dname IN ('SALES', 'RESEARCH');
DNAME ENAME SAL DRANK
RESEARCH SMITH 800 1
RESEARCH ADAMS 1100 2
RESEARCH JONES 2975 3
RESEARCH SCOTT 3000 4
RESEARCH FORD 3000 4
RESEARCH 3500 5
SALES WARD 1250 1
SALES MARTIN 1250 1
SALES TURNER 1500 2
SALES ALLEN 1600 3
SALES BLAKE 2850 4
plsql 내에서 사용 가능 :oracle 9i 부터
SQL> create table
rank_emp(deptno number(2), ename varchar2(20), sal number(5), rk number(2));
테이블이 생성되었습니다.
SQL> create or replace procedure window_plsql AS
query_str VArchar2(1000);
begin
query_str := 'insert into rank_emp
SELECT deptno, ename, sal,
RANK() OVER (PARTITION BY deptno ORDER BY sal DESC, comm) as rk
FROM emp' ;
Execute Immediate query_str;
end;
2 /
프로시저가 생성되었습니다.
SQL> exec window_plsql
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL> select * from rank_emp;
DEPTNO ENAME SAL RK
10 KING 5000 1
10 CLARK 2450 2
10 MILLER 1300 3
20 SCOTT 3000 1
20 FORD 3000 1
20 JONES 2975 3
20 ADAMS 1100 4
20 SMITH 800 5
30 BLAKE 2850 1
30 ALLEN 1600 2
30 TURNER 1500 3
DEPTNO ENAME SAL RK
30 WARD 1250 4
30 MARTIN 1250 5
30 JAMES 950 6
14 개의 행이 선택되었습니다.That's correct
The differences between Standard and Enterprise Edition are listed here:
http://www.oracle.com/technology/products/oracle8i/pdf/8i_fam.pdf -
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? -
Rank Function taking a long time to execute in SAP HANA
Hi All,
I have a couple of reports with rank function which is timing out/ or taking a really long time to execute, Is there any way to get the result in less time when rank functions are involved?
the following is a sample of how the Query looks,
SQL 1:
select a.column1,
b.column1,
rank () over(partition by a.column1 order by sum(b.column2) asc)
from "_SYS_BIC"."Analyticview1" b
join "Table1" a
on (a.column2 = b.column3)
group by a.column1,
b.column1;
SQL 2:
select a.column1,
b.column1,
rank () over( order by min(b.column1) asc) WJXBFS1
from "_SYS_BIC"."Analytic view2" b
cross join "Table 2" a
where (a.column2 like '%a%'
and b.column1 between 100 and 200)
group by a.column1,
b.column1
when I visualize the execution plan,the rank function is the one taking up a longer time frame. so I executed the same SQL without the rank() or partition or order by(only with Sum() in SQL1 and Min() in SQL 2) even that took a around an hour to get the result.
1.Does anyone have an any idea to make these queries to execute faster?
2. Does the latency have anything to do with the rank function or could it be size of the result set?
3. is there any workaround to implement these rank function/partition inside the Analytic view itself? if yes, will this make it give the result faster?
Thank you for your help!!
-GayathriKrishna,
I tried both of them, Graphical and CE function,
It is also taking a long time to execute
Graphical view giving me the following error after 2 hr and 36 minutes
Could not execute 'SELECT ORDER_ID,ITEM_ID,RANK from "_SYS_BIC"."EMMAPERF/ORDER_FACT_HANA_CV" group by ...' in 2:36:23.411 hours .
SAP DBTech JDBC: [2048]: column store error: search table error: [2620] executor: plan operation failed
CE function - I aborted after 40 mins
Do you know the syntax to declare local variable to use in CE function? -
RANK Function in AIX vs Windows
I am facing an issue where when I run my report using my windows machine I am able to get the right results with the RANK function. However, when I ran the same report in my AIX machine, I got the following error:
Odbc driver returned an error (SQLExecDirectW).
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 378077472. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 46008] Internal error: File server/Query/Optimizer/ServiceInterfaceMgr/Src/SQOIGeneratorBuiltIn.cpp, line 3403. (HY000)
If anyone has run into this, please let me know.
Thanks.One point to make is the Rank function works if you create 1 column with the RANK function in Answers(i.e. Rank(Fact.Sales) ). The issue comes up when you try to create a BIN column to bucket the RANKs in a seperate column.
Here's the SQL:
SELECT Location.Location saw_0, case WHEN RANK(Metrics.Sales) BETWEEN 1 AND 5 then '1-5' WHEN RANK(Metrics.Sales) BETWEEN 5 AND 10 then '5-10' else 'other' end saw_1, Metrics.Sales saw_2, RANK(Metrics.Sales) saw_3 FROM "Rank Prototype" ORDER BY saw_0
So Basically, the issue is when you have a Bucketed Rank Sales Column and a simple Rank Column in the same request. (In AIX the issue exists, in Windows there is no issue.) -
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 -
Hi.. i am saravanan working as a software engineer..i am interested in sql.i want to know about the advanced functions in sql ..like cube , over ,rank...etc...if any one explain with good example..it will be very much helpful to me...with thanks and rgds...sarao..
Hi,
For Oracle 10.2 you can check [Analytic Functions|http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions001.htm#i81407].
Regards, -
@Rank function using EVALUATE
Hi short question,
I'm trying to get the @rank function to work in combination with OBIEE 10.1.3.4 (using EVALUATE). Anyone here already tried using this with Essbase version 9.2? In some of the documentation it states this can not be done using anything below Essbase 9.3 but the @Rank function is available within v9.2 Is there any limit on using this from the OBIEE side?
I used this reference:
(how to:) http://oraclebizint.wordpress.com/2008/04/28/oracle-bi-ee-101332-handling-sort-order-in-hyperion-essbase-931-evaluate-and-mdx/
(Essbase 9.2 doc --> @Rank available) http://download.oracle.com/docs/cd/E12032_01/doc/epm.921/html_techref/techref.htm
Evaluate function I'm trying to launch is:
EVALUATE(’RANK(%1.dimension.currentmember,%2.members)’ AS INTEGER,Period."PeriodGen4",Period."PeriodGen4")
Am I doing something wrong here, or am I trying to do things which can't be done?
Thanks in advance,
MathijsI tried the syntax
EVALUATE ('RANK(%1,%2)' as integer,"Account"."Gen4,Account Default","Account"."Gen4,Account Default")
but still i am getting the error as:-
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 96002] Essbase Error: Syntax error in input MDX query on line 6 at token 'RANK' (HY000)
SQL Issued: SELECT s_0, s_1, s_2, s_3, s_4, s_5, s_6, s_7 FROM ( SELECT 0 s_0, "FINRPTC#1"."Account"."Gen3,Account Default" s_1, "FINRPTC#1"."Account"."Gen4,Account Default" s_2, "FINRPTC#1"."FinancialYear"."Gen2,FinancialYear" s_3, "FINRPTC#1"."Period"."Gen3,Period" s_4, EVALUATE ('RANK(%1,%2)' as integer,"FINRPTC#1"."Account"."Gen4,Account Default","Account"."Gen4,Account Default") s_5, "FINRPTC#1"."FINRPTC"."Actual" s_6, REPORT_AGGREGATE("FINRPTC#1"."FINRPTC"."Actual" BY "FINRPTC#1"."Account"."Gen3,Account Default","FINRPTC#1"."Account"."Gen4,Account Default","FINRPTC#1"."FinancialYear"."Gen2,FinancialYear","FINRPTC#1"."Period"."Gen3,Period") s_7 FROM "FINRPTC#1" WHERE (("FinancialYear"."Gen2,FinancialYear" = 'FY12') AND ("Period"."Gen3,Period" = 'Nov') AND ("Account"."Gen3,Account Default" = 'Net Cost of Services')) ) djm -
Compile forms error because using rank function
Hi,
Oracle Form 9i don't known rank function in my SQL statement. When compile forms, it alerts err message: "Encountered the symbol "(" when expecting one ..."
code:
select * from (
select group_id, acct_no, acct_desc, rank() over(order by acct_no desc) rank_no from customer
where group_id='002'
) where rank_no< 10000
Help me ASAP.
Many thank,
Bum.Where is INTO clause ? Plz provide the actual code you are writing.
I think this type of queries not supported in Forms 9i.....try forms 10g or above. -
Cummulative total and rank function
Hi,
I'm using Discoverer 3.1.36 and wondering if there is a way to
get cumulative totals with Discoverer and how
For i.e
column A column B column C
AB 50 50
BC 100 150
MB 70 220
Also how to create the report that will show only top X values
and has rank column too
For i.e
Rank Column A
1 50
2 30
3 15try importing your own sql statement for using the rank
function. you may have to export sql first (to create the sql
file), then edit it and import it.
to get rank, you can try something like this:
SELECT "User Name", "Number of whtvr"
FROM
(SELECT t1.username "User Name", COUNT(*) "Number of whtvr",
RANK() OVER (ORDER BY COUNT(*) DESC nulls last) rank
FROM table1 t1, table2 t2
WHERE t1.userid=t2.userid
AND t1.date BETWEEN t2.start_date AND t2.end_date
GROUP BY t1.username)
WHERE rank <= 10
ORDER BY "Number of whtvr" DESC;
try adding another column to assign a number to each row for the
rank, maybe a sequence generated number, if a rank column (from
the subquery) doesn't work. -
Hello All,
Below is the sql i am trying to execute and the Dense Rank function is giving same result for all of the rows, could you please help me where i am doing wrong
SELECT
AMT,
DENSE_RANK() OVER (PARTITION BY AMT ORDER BY AMT DESC) AS DENSE_RANK
FROM
SELECT DISTINCT
SUM(NVL(TRUNC(NET_AMT) * NVL(GLOBAL1_EXCHANGE_RATE,1),0))
OVER (PARTITION BY CUSTOMER_BILL_TO_LOC_WID ORDER BY CUSTOMER_BILL_TO_LOC_WID)
AS AMT
FROM
W_SALES_BOOKING_LINE_F
WHERE
SALES_ORDER_NUM IN ('10612426','10612450','10612477','32649203')
AND
X_MONTH_WID=TO_CHAR(SYSDATE-1,'YYYYMMDD')
)--ORDER BY AMT DESC Result Set:
AMT DENSE_RANK
0 1
2,855 1
6,706 1
14,265 1you have "broken" up your resultset (from the inline view) by AMT (PARTITION BY AMT)
and per part, you sort this (one row in each partition, not a whole lot of sorting) ( ORDER BY AMT DESC)
then you assign a ranking based on the sorting action... which yields 1 (DENSE_RANK)
Are you looking for this
SELECT
AMT,
DENSE_RANK() OVER (ORDER BY AMT DESC) AS DENSE_RANK
FROM
SELECT DISTINCT
SUM(NVL(TRUNC(NET_AMT) * NVL(GLOBAL1_EXCHANGE_RATE,1),0))
OVER (PARTITION BY CUSTOMER_BILL_TO_LOC_WID ORDER BY CUSTOMER_BILL_TO_LOC_WID)
AS AMT
FROM
W_SALES_BOOKING_LINE_F
WHERE
SALES_ORDER_NUM IN ('10612426','10612450','10612477','32649203')
AND
X_MONTH_WID=TO_CHAR(SYSDATE-1,'YYYYMMDD')
)--ORDER BY AMT DESC -
Want to convert function in SQL Server 2000
Hi ,
i am writing this function in oracle.Could you please convert this function in SQL Server 2000 because i am new in this and dont know how to use decode function in sql.
Please following is the code for oracle.
CREATE OR REPLACE function fun ( localex varchar2,titlex varchar2)
return number
as x number;
begin
select sum ( decode (count (username),max(prereq_count),1,0) ) x into x from
SELECT
prereq_count,
username
FROM
table1
group by username ;
return x;
end fun;
Regards
VishalJust take a look example below might give you idea :
create or replace function f_makeAddress_tx (
i_address_tx VARCHAR2,
i_city_tx VARCHAR2,
i_state_tx VARCHAR2,
i_zip_tx VARCHAR2)
return VARCHAR2
is
e_badZip EXCEPTION; u279E8
pragma EXCEPTION_init(e_badZip,-20998); u279E9
v_out_tx VARCHAR2(256);
begin
p_validateZip (i_zip_tx); u279E12
v_out_tx:= i_address_tx||u2019, u2018|| u279E13
i_city_tx ||u2019, u2018||
i_state_tx ||u2019, u2018||
i_zip_tx;
return v_out_tx; u279E17
exception
when e_badZip then u279E19
return i_zip_tx || u2018: Invalid zip code.u2019;
end;
Regards,
Clint
Maybe you are looking for
-
Hello All, I have a report page with some search item.When I print the page the title does not appear on the output page. How I can print the report and its title on the output page. any quick help please
-
IPod nano (version 1.3.1) won't appear in iTunes or on desktop
Hi everyone. I have had my iPod Nano for about a year, and I've never had any problems until a few days ago, when, for a few hours, my Mac Mini basically seemed to stop recognizing that there was an iPod attached to it. I've tried other USB devices w
-
Streaming videos freezing....
Greetings all: I have all the up to date software, SL and ITUNES, and lately, all of my streaming videos to my wirelessly connected ATV have been freezing. I have looked on the site, and found istumbler to use as a tool; when I opened it to check the
-
This just happened yesterday
-
How to Load a html page into Flex the application?
I want to load separate html page in to my flex application. for example think I am in my shopping cart and I wanna buy something and pay for that.Then I am try to pay they will load a separate html page into my shoipping cart. How can I do that insi