Pl/SQL Rank() function problem
Hello everyone....i hv been using Oracle10g for a while now....
I hv a question which I'm not able to solve now...
I have this query which shows top 3 employee records based on their joiningdate...the older the joiningdate the higher would be his rank.
so i run this query....
select * from(select * rank() over(order by joiningdate desc)daterank from employee) where daterank<=3;
Following error occurs:
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
How do i solve this problem???
Edited by: 781207 on Jul 9, 2010 9:42 PM
Check this query
1 select empno ,deptno,Hiredate,
2 dense_rank() OVER (PARTITION BY deptno ORDER BY hiredate) slno
3* from emp
SQL> /
EMPNO DEPTNO HIREDATE SLNO
7782 10 09-JUN-81 1
7839 10 17-NOV-81 2
7934 10 23-JAN-82 3
7369 20 17-DEC-80 1
7566 20 02-APR-81 2
7902 20 03-DEC-81 3
7788 20 19-APR-87 4
7876 20 23-MAY-87 5
7499 30 20-FEB-81 1
7521 30 22-FEB-81 2
7698 30 01-MAY-81 3
EMPNO DEPTNO HIREDATE SLNO
7844 30 08-SEP-81 4
7654 30 28-SEP-81 5
7900 30 03-DEC-81 6
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select empno ,deptno,Hiredate,
2 dense_rank() OVER (ORDER BY hiredate) slno
3* from emp
SQL> /
EMPNO DEPTNO HIREDATE SLNO
7369 20 17-DEC-80 1
7499 30 20-FEB-81 2
7521 30 22-FEB-81 3
7566 20 02-APR-81 4
7698 30 01-MAY-81 5
7782 10 09-JUN-81 6
7844 30 08-SEP-81 7
7654 30 28-SEP-81 8
7839 10 17-NOV-81 9
7900 30 03-DEC-81 10
7902 20 03-DEC-81 10
EMPNO DEPTNO HIREDATE SLNO
7934 10 23-JAN-82 11
7788 20 19-APR-87 12
7876 20 23-MAY-87 13
14 rows selected.
SQL>
Similar Messages
-
RANK() function problem in Form 10g
I am using form 10g R2. I wrote codes inside a trigger of a button to select from one table, named test. The code is as follows:
select mm,pp,rr from test. The form can compile this code.
But when I write teh code select mm,pp, rank() over(order by pp desc) rr from test, the form can not compile. Itshows the following error:
Encountered the sysmbol "(" when expecting one of the following:
, from into bulk.
The table has only one record. It works in SQL environment but the form can not compile this RANK() OVER() function.
Do you have any idea to use RANK() OVER() function in Form 10g?Some analytical functions do not work in client-side sql in forms, you'll have to encapsulate your logic in the database.
-
Sql query/function problem??
Hi ,
I have problems writing a difficult sql query, please help me
I have a table t in which there are 50000 records
the table has columns like
create table t
(MATCH_ID NUMBER(4) NOT NULL,
TEAM_ID NUMBER(4),
PLAYER_ID NUMBER(4),
RUNS NUMBER(3))
here match_id, player_id and team_id are jointly primary key
SQL> SELECT * FORM T WHERE MATCH_ID < 10
MATCH_ID TEAM_ID PL_ID RUNS
1 2 1228 8
1 2 1203 82
1 2 1316 24
1 1 1150 27
1 1 1278 13
1 1 1243 60
2 1 1278 37
2 1 1291 0
2 1 1243 53
2 2 1228 25
2 2 1285 103
2 2 1316 60
3 2 1228 8
3 2 1285 25
3 2 858 43
3 1 1278 52
3 1 1394 6
3 1 1243 31
4 1 1278 61
4 1 1394 6
4 1 1243 3
4 2 1228 41
4 2 1285 40
4 2 858 5
6 2 1228 20
6 2 1285 100
6 2 1408 0
7 2 1228 15
7 2 1285 34
7 2 1408 44
8 2 1228 0
8 2 1420 31
8 2 1340 66
9 2 1420 19
9 2 1385 28
9 2 1340 0
.....so on upto 50000 records..
the problem is that I want to extract how many times each player_id in each
match exists in the table, prior to that match_id (or current_match_id)
along with that in another column, I also want the sum of 'RUNS' for each
player_id prior to that match_id (or current_match_id)
my disired output is:
MATCH_ID TEAM_ID player_ID RUNS NO_OF_OCCURENCES SUM(RUNS)
BEFORE_THIS_MATCH BEFORE_THIS_MATCH
FOR_THIS_PLAYER_ID FOR_THIS_PLAYER_ID
1 2 1228 8 0 0
1 2 1203 82 0 0
1 2 1316 24 0 0
1 1 1150 27 0 0
1 1 1278 13 0 0
1 1 1243 60 0 0
2 1 1278 37 1 13
2 1 1291 0 0 0
2 1 1243 53 1 60
2 2 1228 25 1 8
2 2 1285 103 0 0
2 2 1316 60 1 24
3 2 1228 8 2 33
3 2 1285 25 1 103
3 2 858 43 0 0
3 1 1278 52 2 50
3 1 1394 6 0 0
3 1 1243 31 2 113
4 1 1278 61 3 102
4 1 1394 6 1 6
4 1 1243 3 3 144
4 2 1228 41 3 41
4 2 1285 40 2 128
4 2 858 5 1 43
6 2 1228 20 4 82
6 2 1285 100 3 168
6 2 1408 0 0 0
7 2 1228 15 5 102
7 2 1285 34 4 268
7 2 1408 44 1 0
8 2 1228 0 6 117
8 2 1420 31 0 0
8 2 1340 66 0 0
9 2 1420 19 1 31
9 2 1385 28 0 0
9 2 1340 0 1 66
as you can see from the above data (5TH COLUMN), i have mentioned the
existance of each player_id in each match prior to the current_match_id
since match_id = 1 is the 1st match in the table so no player_id comes in the
table before match number 1.
In match number 2 , player_id = 1278 was also present in match_id = 1 so
thats why Number_OF_OCCURENCES = 1 for player_id = 1278 in match_id = 2
and so on..
same is the case with 'RUNS' column but here RUNS are the SUM of each
player_id's 'RUNS' before the current match
Note: if some player_id does not exist in the table before the current
match_ID then the query should return zero for that player_id ( as in 4th and
5th columns of no_of_occurances and sum(runs) respectively)
for example: in above data
MATCH_ID TEAM_ID PLayer_ID RUNS NO_OF_OCCURENCES SUM(RUNS)
BEFORE_THIS_MATCH BEFORE_THIS_MATCH
FOR_THIS_PLAYER_ID FOR_THIS_PLAYER_ID
9 2 1385 28 0 0
I hope this will clear my problem
i would be extremely grateful if someone helps me out??
here is sample ddl of the above data
create table t
(MATCH_ID NUMBER(4) NOT NULL,
TEAM_ID NUMBER(4),
PLAYER_ID NUMBER(4),
RUNS NUMBER(3))
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1228, 8);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1203, 82);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1316, 24);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1150, 27);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1278, 13);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1243, 60);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1278, 37);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1291, 0);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1243, 53);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1228, 25);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1285, 103);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1316, 60);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1228, 8);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1285, 25);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 858, 43);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1278, 52);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1394, 6);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1243, 31);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1278, 61);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1394, 6);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1243, 3);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1228, 41);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1285, 40);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 858, 5);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1228, 20);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1285, 100);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1408, 0);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1228, 15);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1285, 34);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1408, 44);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1228, 0);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1420, 31);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1340, 66);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1420, 19);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1385, 28);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1340, 0);regards
ramis.Ramis,
SQL> select * from tt;
MATCH_ID TEAM_ID PLAYER_ID RUNS
1 2 1228 8
1 2 1203 82
1 2 1316 24
1 1 1150 27
1 1 1278 13
1 1 1243 60
2 1 1278 37
2 1 1291 0
2 1 1243 53
2 2 1228 25
2 2 1285 103
2 2 1316 60
3 2 1228 8
3 2 1285 25
3 2 858 43
3 1 1278 52
3 1 1394 6
3 1 1243 31
4 1 1278 61
4 1 1394 6
4 1 1243 3
4 2 1228 41
4 2 1285 40
4 2 858 5
6 2 1228 20
6 2 1285 100
6 2 1408 0
7 2 1228 15
7 2 1285 34
7 2 1408 44
8 2 1228 0
8 2 1420 31
8 2 1340 66
9 2 1420 19
9 2 1385 28
9 2 1340 0
36 rows selected.
SQL> select tt.match_id,
tt.team_id,
tt.player_id,
tt.runs,
nvl(a.sum_player,0) OCC,
nvl(b.sum_runs,0) SUM_RUNS
from
tt,
(select a.match_id,a.team_id,a.player_id,a.runs,count(*) sum_player
from tt a,
(select match_id,player_id
from tt
group by match_id,player_id) b
where a.match_id>b.match_id
and a.player_id=b.player_id
group by a.match_id,a.team_id,a.player_id,a.runs
) a,
(select a.match_id,a.team_id,a.player_id,a.runs,sum(b.runs) sum_runs
from tt a,
(select match_id,player_id,runs
from tt) b
where a.match_id>b.match_id
and a.player_id=b.player_id
group by a.match_id,a.team_id,a.player_id,a.runs
) b
where tt.match_id=a.match_id(+)
and tt.team_id=a.team_id(+)
and tt.player_id=a.player_id(+)
and tt.match_id=b.match_id(+)
and tt.team_id=b.team_id(+)
and tt.player_id=b.player_id(+)
MATCH_ID TEAM_ID PLAYER_ID RUNS OCC SUM_RUNS
1 1 1150 27 0 0
1 1 1243 60 0 0
1 1 1278 13 0 0
1 2 1203 82 0 0
1 2 1228 8 0 0
1 2 1316 24 0 0
2 1 1243 53 1 60
2 1 1278 37 1 13
2 1 1291 0 0 0
2 2 1228 25 1 8
2 2 1285 103 0 0
2 2 1316 60 1 24
3 1 1243 31 2 113
3 1 1278 52 2 50
3 1 1394 6 0 0
3 2 858 43 0 0
3 2 1228 8 2 33
3 2 1285 25 1 103
4 1 1243 3 3 144
4 1 1278 61 3 102
4 1 1394 6 1 6
4 2 858 5 1 43
4 2 1228 41 3 41
4 2 1285 40 2 128
6 2 1228 20 4 82
6 2 1285 100 3 168
6 2 1408 0 0 0
7 2 1228 15 5 102
7 2 1285 34 4 268
7 2 1408 44 1 0
8 2 1228 0 6 117
8 2 1340 66 0 0
8 2 1420 31 0 0
9 2 1340 0 1 66
9 2 1385 28 0 0
9 2 1420 19 1 31
36 rows selected.
SQL> Is this do you want ?
Nicolas. -
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> -
Problem with SQL Convert Function Junk Character
Hi All,
We have a database field that has a value of “2.020 OPERATOE’S CAB – GLASSES” on the front end of Oracle E-Business Suite. When we are spooling that column(in PLSQL) with the SQL covert function , one of the characters(’) in the string is not getting converted properly. It is displayed as a junk character in the spooled file.
We used CONVERT(p_column,'WE8ISO8859P1','UTF8') for converting the string and utl_file api for spooling the output file. Please note that converted string is passed to utl_file.fopen directly.
Following are the nls_parameters values.
NLS_CHARACTERSET ~~ UTF8
NLS_NCHAR_CHARACTERSET ~~ AL16UTF16
Any inputs are welcome.
Thanks
gt1942Hello All,
Sorry, If I am opening the blog in the wrong place as this is the first time.
my out looks as follows.
"02920Â "
but when i see in the application there is nuthing in the end.
so I used regexp_replace(p_vendor_dtl,'[^[!-~]]*',''), But this is removing spaces also. I don't want to remove space. I want to remove this character only.
Please help
Thanks. -
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 -
Query of queries disallows SQL right() function
We're attempting to do a query of queries using the SQL
right() function like this:
select *
from getresults
where right([key],charindex('\',reverse([key]),1)-1) not in
(#quotedvaluelist(getexcluded.file_name)#)
We've even replaced that where clause with a much more simple
where right([key])='m'
just to make sure that it wasn't the nesting functions that
were causing the problem.
In either case, we get the error:
Query of Queries syntax error.
Encountered "right" at line 0, column 0. Incorrect
conditional expression,
Expected one of [like|null|between|in|comparison] condition,
What SQL functions are disallowed from query of queries?
Thanks,
KrisNasty stuff huh. Just happened to discover myself today that
Left doesn't work. I'd suspect that Aggregate functions are the
ONLY ones that will work. It would have been nice if they'd at
least allowed CF vs DB functions in their own "database" language.
BTW, also discovered that Count() returns Null rather than 0
when there aren't any per your WHERE clause. -
Rank function without filter in the report
Hi,
I have a problem with Rank() function. The problem is the next one.
I have a table with this rows:
User | DATE | Cost
user1 | 12/02/2011 | 10,4
user1 | 13/02/2011 | 11,1
user1 | 13/02/2011 | 10,1
user1 | 13/02/2011 | 8,1
user2 | 12/02/2011 | 1,4
user2 | 13/02/2011 | 12,1
user2 | 13/02/2011 | 22,1
user2 | 13/02/2011 | 8,1
In the rpd I have a agregate row as SUM(COST), and I need extract te ranking of this SUM(COST) per user, The sum of user1 is 39,7 and the sum of the user 2 is 43,7. If I show in the report all users, the ranking is correct Rank=1 per user2 and Rank=2 per user1, but the problem is that I only want show the user1, when I add a filter to the report user='user1' the ranking value changes from 2 to 1. I need that the ranking value doesn´t change when I introduce a filter.
Any idea about how to solve this problem?
ThanksHi Antonio,
On the Rank column in the answers edit the formula as given below.
Case when username = 'user2' then Rank(sum(cost)) else 0 end
Then apply a filter on the Rank column as Rank > 0.
I hope this one helps you.
Regards
AP -
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? -
I'm trying to rank products based on the order in which they have been bought (by purchase date).
I figured out I could use the Rank function. First problem was that Rank doesn't seem to work on Dates. I have come across this issue by using the DaysBetween function to calculate the days inbetween the first purchase date and today. This gives me a measure that I can use within the Rank function.
Works fine for single Dimention values. However, when I create a cross-tab with multiple values on top, this doesn't work anylonger.
See the example that shows where it goes wrong: [http://www.littlesister.com/example.xls]
Does anyone have any idea how to solve this?
Thanks,
PaulPaul,
In the crosstab with the multiple values remove the sort on the rank (if it is still on) and put a break on the object which shows the data for Americas, AP, EMEA and WW.
That should show the correct ranking (at least it does in an example I build myself).
Regards,
Harry -
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 -
Improve built in SQL MAX function
Hi
I am trying to improve the performance of the built in SQL max function. right now searching through over 500,000 rows takes lot of time which can be reduced. Can anyone suggest me something which would be helpful in this or may be give me a link if it has been discussed before?
Anything is appreciated.
ThanksTolls wrote:
Um...considering you were planning on improving on the MAX function, I sort of thought you might actually know how to use it. Otherwise how would you know it was running slowly?thanks Tolls i'd figured it out right after i posted it. i guess i was too excited after reading (you got it in milliseconds) that posted right away without doing anything myself..but yeah it did make it super fast..thanks a lot for your help and time..
cotton.m wrote:
d_khakh wrote:
hi tolls thanks for getting back
could u explain how did u do that? i found out how to create index..i have the following statement:
create index col on table2 (col2);
cud u tell me how to go from here and find the max in col2..thanks again for ur help?
sigh
Where to go from here? Just execute your damn query. If you really did create the index on the right column and your database isn't stupid and there isn't a lot more to this problem then you told us about like some where clauses then that's it. She's as fast as she's going to get.
And remember, it's impolite to converse in a public forum while chewing your cud. Unless of course you actually meant "could" but were just too lazy to type it. Don't be lazy, use full words. Thanks.like i said above..i figured it out after some time.
i wasn't being lazy ..thats msn talk..i thought people understood that..anyways your point noted too.
Maybe you are looking for
-
BAPI -for Creating EXCISE INVOICE AT DEPOT tcode 'J1IG
Hi All, Is there any BAPI for Excise Invoice Creation at depot Tcode is J1IG Thanks, Satishreddy
-
HT201250 backup ipod with time machine
I need to back-up my iPoad Classic 160gb BUT iTunes does not give me this option unless I am trying to restore it (which is weird because it's never been backed up so how can it restore it?). Can I backup my 160 gb iPoad using Time Machine, to an ext
-
Hi all, I am posting this message again. I would appreciate any help, as I am stuck with a customer issue. This method hangs for the following values read(xchar, 0, 1) Does not throw any exception. The inputstream does have data in it. the characters
-
Events won't load from new to old
My events will not change from old to new even when I uncheck in the view menu.
-
How to make a chart/table a background object?
How do I make that grid into a background objective so that I can draw lines and similar things on top of it without it moving? Intending to use it as a coordinate system/grid/plane (or whatever it is called in English, but the thing refuses to stay