Over Partition by in OWB 9i
Hi,
I am using OWB V9i. I need to implement an sql statement in a mapping.The statement is
CASE WHEN (tr_dt=lead(tr_dt) OVER(PARTITION BY ID ORDER BY ID,tr_dt))
THEN lead(ef_dt) OVER(PARTITION BY ID ORDER BY ID,tr_dt)
ELSE tr_dt
END
I am not able to put the case statement in an expression as it has OVER PARTITION BY which the expression operator is not accepting. Is there any way i can implement the same in the mapping without using a table function or any other procedure???
Regards
Bharath
OWB's support for analytics has always been pretty sparse. They did release a doc that showed a way to build some analytics using various workarounds here:
http://www.oracle.com/technology/sample_code/products/warehouse/files/analyticfunctions.pdf
However my approach has always been to tend towards simplicity. A convoluted "workaround"mapping is harder to tune, troubleshoot, or maintain, and I always worry about how OWB will handle such workarounds over subsequent release upgrades. So, for anything not clearly natively supported by OWB - I build a view with the analytic and use that as my source.
Mike
Similar Messages
-
Case Statement in Analytic Function SUM(n) OVER(PARTITION BY x)
Hi Guys,
I have the following SQL that doesn't seem to consider the When clause I am using in the case staement inside the analytic function(SUM). Could somebody let me know why? and suggest the solution?
Select SUM(Case When (A.Flag = 'B' and B.Status != 'C') Then (NVL(A.Amount_Cr, 0) - (NVL(A.Amount_Dr,0))) Else 0 End) OVER (PARTITION BY A.Period_Year) Annual_amount
, A.period_year
, B.status
, A.Flag
from A, B, C
where A.period_year = 2006
and C.Account = '301010'
--and B.STATUS != 'C'
--and A.Flag = 'B'
and A.Col_x = B.Col_x
and A.Col_y = C.Col_y
When I use this SQL, I get
Annual_Amount Period_Year Status Flag
5721017.5 --------- 2006 ---------- C -------- B
5721017.5 --------- 2006 ---------- O -------- B
5721017.5 --------- 2006 ---------- NULL ----- A
And when I put the conditions in the where clause, I get
Annual_Amount Period_Year Status Flag
5721017.5 ---------- 2006 ---------- O -------- BHere are some scripts,
create table testtable1 ( ColxID number(10), ColyID number(10) , Periodname varchar2(15), Flag varchar2(1), Periodyear number(15), debit number, credit number)
insert into testtable1 values(1, 1000, 'JAN-06', 'A', 2006, 7555523.71, 7647668)
insert into testtable1 values(2, 1001, 'FEB-06', 'B', 2006, 112710, 156047)
insert into testtable1 values(3, 1002, 'MAR-06', 'A', 2006, 200.57, 22376.43)
insert into testtable1 values(4, 1003, 'APR-06', 'B', 2006, 0, 53846)
insert into testtable1 values(5, 1004, 'MAY-06', 'A', 2006, 6349227.19, 6650278.03)
create table testtable2 ( ColxID number(10), Account number(10))
insert into testtable2 values(1, 300100)
insert into testtable2 values(2, 300200)
insert into testtable2 values(3, 300300)
insert into testtable2 values(4, 300400)
insert into testtable2 values(5, 300500)
create table apps.testtable3 ( ColyID number(10), Status varchar2(1))
insert into testtable3 values(1000, 'C')
insert into testtable3 values(1001, 'O')
insert into testtable3 values(1002, 'C')
My SQL:
select t1.periodyear
, SUM(Case When (t1.Flag = 'B' and t3.Status != 'C') Then (NVL(t1.credit, 0) - (NVL(t1.debit,0))) Else 0 End) OVER (PARTITION BY t1.PeriodYear)
Annual_amount
, t1.flag
, t3.status
, t2.account
from testtable1 t1, testtable2 t2, testtable3 t3
where t1.colxid = t2.colxid
and t1.colyid = t3.colyid(+)
--and t1.Flag = 'B' and t3.Status != 'C'
Result:
PeriodYear ----- AnnualAmount ----- Flag ----- Status ----- Account
2006 ------------------ 43337 --------------- A ----------- C ---------- 300100
2006 ------------------ 43337 --------------- B ----------- O ---------- 300200
2006 ------------------ 43337 --------------- A ----------- C ---------- 300300
2006 ------------------ 43337 --------------- B ------------ ----------- 300400
2006 ------------------ 43337 --------------- A ------------ ----------- 300500
With condition "t1.Flag = 'B' and t3.Status != 'C'" in where clause instead of in Case statement, Result is (which is desired)
PeriodYear ----- AnnualAmount ----- Flag ----- Status ----- Account
2006 ------------------ 43337 --------------- B ----------- O ---------- 300200 -
Are there any MDX gurus who can help me?
I am trying to produce an MDX query that generates a ranked result set, within this I am trying to get two levels of ranking based on Net Sales, firstly the ranking within the overall set, and secondly a ranking partitioned by an attribute dimension (the equivalent of RANK () OVER (PARTITION BY ...) in SQL Server), with the final result set sorted alphabetically by the attribute name and secondly by Net Sales. So far I have got the sorting and the overall ranking to work but not the partitioned rank. Any solution will need to be fast as the base dimension has 100K members.
My current MDX looks like this:
WITH
SET [Divisions] AS '[AttributeContract].[Att_CC01].Children'
SET [ContractsByDiv] AS
'GENERATE(
ORDER(
[AttributeContract].[Att_CC01].Children,
AttributeContract.CurrentMember.[MEMBER_NAME],
BASC
CROSSJOIN(
AttributeContract.CurrentMember
ORDER(
NonEmptySubset(
UDA([Entity].[Entity Contract Reporting], "Contract")
[Net Sales],
BDESC
MEMBER [Account].[Overall Rank] AS 'Rank([ContractsByDiv].CurrentTuple,[ContractsByDiv],[Net Sales])'
MEMBER [Account].[Rank In Div] AS '1'
SELECT
[Net Sales]
,[Overall Rank]
,[Rank In Div]
} ON COLUMNS,
[ContractsByDiv]
} ON ROWS
FROM HCREPRT2.Analysis
WHERE
[Year].[FY13],
[Period].[BegBalance],
[ISBN Type].[Total ISBN Type],
[Lifecycle].[Front List],
[Scenario].[DPG_Budget],
[Market].[Total Market],
[Version].[Working],
[Sales Channel].[Total Sales Channel]
Any suggestions as to how to do this or whether it is possible?
Regards,
Gavin
Edited by: GavinH on 07-Mar-2012 02:57This was the solution I came up with:
The following query returns a result set with the the data ranked across the overall set and with a ranking partioned by division:
WITH
SET [Divisions] AS 'ORDER([AttributeContract].[Att_CC01].Children,AttributeContract.CurrentMember.[MEMBER_NAME],BASC)'
SET [EntitySet] AS 'ORDER(NonEmptySubset(UDA([Entity].[Entity Contract Reporting], "Contract")),[Net Sales],BDESC)'
SET [ContractsByDiv] AS
'GENERATE(
[Divisions],
CROSSJOIN(
AttributeContract.CurrentMember
NonEmptySubset([EntitySet])
-- Rank in whole data set
MEMBER [Account].[Overall Rank] AS 'Rank([ContractsByDiv].CurrentTuple,[ContractsByDiv],[Net Sales])'
-- Ranking in division
MEMBER [Account].[Rank In Div] AS
'Rank(
([AttributeContract].CurrentMember,[Entity].[Entity Contract Reporting].CurrentMember),
CROSSJOIN(
AttributeContract.CurrentMember
NonEmptySubset([EntitySet])
[Net Sales]
-- Rownumber
MEMBER [Account].[RowNumber] AS 'RANK([ContractsByDiv].CurrentTuple,[ContractsByDiv],1,ORDINALRANK)'
SELECT
[Net Sales]
,[Overall Rank]
,[Rank In Div]
,[RowNumber]
} ON COLUMNS,
[ContractsByDiv]
} ON ROWS
FROM HCREPRT2.Analysis
WHERE
[Year].[FY13],
[Period].[BegBalance],
[ISBN Type].[Total ISBN Type],
[Lifecycle].[Front List],
[Scenario].[DPG_Budget],
[Market].[Total Market],
[Version].[Working],
[Sales Channel].[Total Sales Channel]
The key was to use the cross join portion of the generate statement used to create the overall set as the set for the intra divisional ranking. -
Analytical function SUM() OVER (PARTITION BY ) in Crosstab
I am trying to resolve this from a very long time. I have an amount column that has to be grouped on Year, but all the other columns grouped by month. I am trying to achieve this using analytic function SUM(Case when (Condition1 and Condition2) then Sum(Amount) else 0 end) OVER ( PARTITION BY Account, Year), Where Account, Sub Account are the left axis columns. Now, column displays the values correctly, but at different rows. This is confusing.............
For Ex: For Account 00001, there are 3 sub accounts 1000,2000,3000. For Sub account 3000, conditions 1 and 2 are satisfied, so it should display the Amount in the row corresponding to Sub account 3000, and 0 for remaining Sub Accounts. And the Total amount of all the sub accounts, which will be the same as amount for SubAccount 3000 should be displayed in the row corresponding to Account 00001.
But I get blank rows for 1000 and 3000 Sub accounts and Amount displayed in 2000 Sub account, and blank for Account 00001 also.
When I created the same workbook in Tabular form, the same amount is displayed for all the SubAccounts of a single Account.
When I used this CASE statement in TOAD, I figured that this is due to the Analytic function. When I use a group by clause as shown below instead of partition by, I get the results I need.
SELECT (Case when (Condition1 and Condition2) then Sum(Amount) else 0 end), Account, Sub Account FROM tables WHERE conditions GROUP BY Year, Account, Sub Account
But I cannot use groupby for whole SQL of the workbook as I need the other columns with page item 'MONTH' not 'Year'.
Could somebody please help me with this?Hi,
In your tabular form do you get the correct total display against all you subaccounts and account? If this correct then you can use case to ensure that the total is displayed only for the single account.
Once you have the correct totals working in a tabular form it is easier to re-produce what you want in a cross-tab.
Rod West -
Group by and over partition.
Hi to everybody....
i ahev a table like this:
id name salary
1 John 1000
2 Tom 1300
3 Alan 1400
4 Mark 1800
and i do a query like this:
select max(salary) from table
and i have 1800
What i would like to have, is a query that return me the id, the name and the max salary.
i can do
select * from
select max(salary) as max from table) AAA,
table
where AAA.max =table.salary.
But i would like to do it in only one query using the group by expression and over partition statement.
Thank's in advance to everybody!Flavio,
You can use...
sql> select max(sal) from emp;
MAX(SAL)
5000
sql> select empno, ename, max(sal) over () from emp;
EMPNO ENAME MAX(SAL)OVER()
7369 SMITH 5000
7499 ALLEN 5000
7521 WARD 5000
7566 JONES 5000
7654 MARTIN 5000
7698 BLAKE 5000
7782 CLARK 5000
7788 SCOTT 5000
7839 KING 5000
7844 TURNER 5000
7876 ADAMS 5000
EMPNO ENAME MAX(SAL)OVER()
7900 JAMES 5000
7902 FORD 5000
7934 MILLER 5000If you need to have the max per department , you just would need to add....
1* select empno, ename, max(sal) over (partition by deptno) from emp
sql> /
EMPNO ENAME MAX(SAL)OVER(PARTITIONBYDEPTNO)
7782 CLARK 5000
7839 KING 5000
7934 MILLER 5000
7566 JONES 3000
7902 FORD 3000
7876 ADAMS 3000
7369 SMITH 3000
7788 SCOTT 3000
7521 WARD 2850
7844 TURNER 2850
7499 ALLEN 2850
EMPNO ENAME MAX(SAL)OVER(PARTITIONBYDEPTNO)
7900 JAMES 2850
7698 BLAKE 2850
7654 MARTIN 2850HTH,
Rajesh. -
Issue with ROW_NUMBER() OVER (PARTITION)
Hi,
Please read the Thread completely, I have created a Report to see Yearly Turnover%, The report works fine but when I take Quarter and Months in it, it restricts the result to only 1 line(i.e., my first year's Turnover) and when I opened the Physical query, I saw the BI Server is using
ROW_NUMBER() OVER (PARTITION BY)
which is not at all necessary.
*I tried disabling WITH_CLAUSE_SUPPORTED and PERF_PREFER_MINIMAL_WITH_USAGE but didn't get any resolution, Could anybody help me out?
thanks in Advance,
AnandYou said 'it restricts the result to only 1 line' means the value is nor drill down to next level?
In that case Yearly Turnover% is set to Year level? -
Need help converting SQL "OVER (PARTITION BY )" to JPQL equivalent - JPA
Having trouble converting this query:
select
sdi,
val,
vldtn,
TO_CHAR(sdt, 'yyyy-mm-dd hh:mi:ss AM')
from
select
sdi,
val,
vldtn,
sdt,
max(sdt) over (partition by sdi) as MaxDate1
from
r_ins
) x
where x.sdt = x.MaxDate1
and sdi in (1234,2345,3456,4567,5678,6789,7890);
to JPQL equivalent using JPA
Able to convert simple queries but I do not know how to handle the "over (partition by sdi)" portion of the query.
Can anyone help
TIA
JerPaul Horth wrote:
Why have the power (and cost) of Oracle and then not use those powerful features because you are restricting yourself to a vanilla set of SQL because you are using some generic framework.You know how it is :
1 - Application developers create code & queries but only test them on tiny database with low volume and no concurrency at all.
2 - Application goes Live, Database grows (as expected) but stupid optimizer is not as fast as on test environment (that was mostly empty)
3 - Queries are now 200 times slower.
4 - Expensive DB expert comes and gathers statistics, creates indexes, rewrites queries, uses hint/outline/SQLprofile.
Conclusion : Database is evil and prevent application from working efficiently, the proof of all that being : nothing had to be done on application's side to make things work correctly. Database is declared guilty.
Which could translate to :
1 - Team buy a formula one with 800HP that can reach 200mph in less than 10 seconds.
2 - Give it a pilot that doesn't even want to understand what-the-heck is a gearbox/transmission. Pilot only drives in 1st gear.
3 - The formula one is now doing 0.003 miles per gallon, doing the hell of a noise, and is limited to 80mph +(any $10000 family wagon is faster in average)+
4 - Expensive expert comes and check everything in the formula one. Finally understand the problem and modify the gearbox to a sloppy automatic transmission
Conclusion : Formula 1 is evil and prevent pilot from being fast. The proof of that being : nothing had to be changed on pilot's side to make things work correctly. Formula 1 is declared guilty.
You cannot win race without understanding how the car/engine/transmission/physics/race rules work.
Too much levels of abstraction is bad. Treating the database as a black box is the most seen "Bad Idea" these days (to my point of view).
Warning: I am biased towards Oracle :-)And so am I.
(^_^) -
Issue with OBIEE ROW_NUMBER() OVER (PARTITION BY)
Hi All,
I am facing some issue with the ROW_NUMBER() OVER (PARTITION BY function in the query that is being generated. I am currently on version 11.1.1.6. I have 1 FACT and 1 Dimension table. Within the dimension I have create a level based hierarchy namely REGION -> GROUP - DIVISION etc. Now the problem is that the OBIEE automatically applies *"ROW_NUMBER() OVER (PARTITION BY T9.PRODUCT_TYPE_DESC, T130.DIVISION_DESC, T130.REGION_DESC ORDER BY T9.PRODUCT_TYPE_DESC ASC, T130.DIVISION_DESC ASC, T130.REGION_DESC ASC) "
to the query where in it is not required at it returns with 3 different row numbers. If i remove this line and the where clause I am able to get correct results however its not working whatever I do in the RPD. Please advise.
WITH
SAWITH0 AS (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
from
(select sum(T157.PL_GRAND_TOTAL) as c1,
sum(T157.TRANSACTION_AMT) as c2,
T130.DIVISION_DESC as c3,
T130.REGION_DESC as c4,
T130.GROUP_DESC as c5,
T9.PRODUCT_TYPE_DESC as c6,
ROW_NUMBER() OVER (PARTITION BY T9.PRODUCT_TYPE_DESC, T130.DIVISION_DESC, T130.REGION_DESC ORDER BY T9.PRODUCT_TYPE_DESC ASC, T130.DIVISION_DESC ASC, T130.REGION_DESC ASC) as c7
from
DIM_ALL_MODULES_REF T9,
DIM_MIS_TREE_REF T130,
DIM_DATE_SERIES T123,
FCT_ALL_MODULES_TRANS T157
where ( T9.SGK_MIS_ID = T130.SGK_MIS_ID and T9.SGK_MODULE_ID = T157.SGK_MODULE_ID and T123.SGK_TIME_ID = T157.SGK_TIME_ID and T123.TRANS_DATE between TO_DATE('2011-01-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2011-03-31 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
group by T9.PRODUCT_TYPE_DESC, T130.DIVISION_DESC, T130.GROUP_DESC, T130.REGION_DESC
) D1
where ( D1.c7 = 1 ) ),
SACOMMON42934 AS (select T130.DIVISION_DESC as c2,
T130.REGION_DESC as c3,
T130.GROUP_DESC as c4,
T9.PRODUCT_TYPE_DESC as c5,
sum(T258.BEG_NMK_EQ_COST_AMT) as c6,
T123.TRANS_DATE as c7,
sum(T258.END_NMK_EQ_COST_AMT) as c8
from
DIM_ALL_MODULES_REF T9,
DIM_MIS_TREE_REF T130,
DIM_DATE_SERIES T123,
FCT_MODULES_BEG_END_BAL T258
where ( T123.SGK_TIME_ID = T258.SGK_TIME_ID and T9.SGK_MIS_ID = T130.SGK_MIS_ID and T9.SGK_MODULE_ID = T258.SGK_MODULE_ID and T258.PRODUCT_TYPE_ID = 2 and T123.TRANS_DATE between TO_DATE('2011-01-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2011-03-31 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
group by T9.PRODUCT_TYPE_DESC, T123.TRANS_DATE, T130.DIVISION_DESC, T130.GROUP_DESC, T130.REGION_DESC),Hi Dhar,
Thanks for replying back. But the ROW_NUMBER thing is inserted with the "WITH SUPPORTED" clause only but that is something which are the default settings. However, I notice that ROW_NUMBER() OVER (PARTITION BY) lines are erratic and are not consistent. So sometimes the drill works properly when no ROW_NUMBER() OVER (PARTITION BY) is generated but other times data is wrong. I am not sure why this behaviour is erratic even though I select the same values.
This is surely a product problem as the condition where c7 = 1 filters the result and does not take into account all values.
Even when I do not use WITH_SUPPORTED clause the stitch does not happen properly. Please advice if this is ever going to be by Oracle or any work around for this?
Thanks -
How to use expression in over partition function
sum(a) over(partition by b order by c range between interval '1' day following and '7' day following)
the above query works fine
but i want to use like this
sum(a) over(partition by b order by c range between interval Trunc(Trunc(sysdate,'MONTH')+1,'MONTH') day following and '7' day following)
is it work ??Balaji.tk wrote:
is it work ??Have you tried it? If not, have a go. ;) -
Over partition: how to use to return the max of two columns
For each unique id, I want to select the value of col2 in the record with the most recent date.
When the rows with the same IDs have the same dates, I want the max value from col2.
I want one row for each ID, but I'm getting two rows for ID 3333333.
with data as
select 1111111 as id, 'a' as col2, to_date('01-JAN-09','dd-mon-yyyy') as the_date from dual union all
select 2222222 as id, 'b' as col2, to_date('02-JAN-09','dd-mon-yyyy') as the_date from dual union all
select 2222222 as id, 'c' as col2, to_date('03-JAN-09','dd-mon-yyyy') as the_date from dual union all
select 2222222 as id, 'd' as col2, to_date('04-JAN-09','dd-mon-yyyy') as the_date from dual union all
select 3333333 as id, 'e' as col2, to_date('05-JAN-09','dd-mon-yyyy') as the_date from dual union all
select 3333333 as id, 'f' as col2, to_date('05-JAN-09','dd-mon-yyyy') as the_date from dual
select id, col2, the_date
from
select id, the_date, col2, max(the_date) over (partition by id) as max_the_date, max(col2) over (partition by col2) as max_col2
from data
where the_date = max_the_date and col2 = max_col2 order by id
Expecting this:
ID COL2 THE_DATE
1111111 a 1/1/0009
2222222 d 1/4/0009
3333333 f 1/5/0009
but I'm getting 2 rows for ID 3333333
Any suggestions?TRy this code without subquery
SELECT ID, MAX (the_date)KEEP (DENSE_RANK LAST ORDER BY the_date),
MAX (col2)KEEP (DENSE_RANK LAST ORDER BY the_date)
FROM DATA
GROUP BY ID
ORDER BY ID
SQL> WITH DATA AS
2 (SELECT 1111111 AS ID, 'a' AS col2,
3 TO_DATE ('01-01-2009', 'dd-mm-yyyy') AS the_date
4 FROM DUAL
5 UNION ALL
6 SELECT 2222222 AS ID, 'b' AS col2,
7 TO_DATE ('02-01-2009', 'dd-mm-yyyy') AS the_date
8 FROM DUAL
9 UNION ALL
10 SELECT 2222222 AS ID, 'c' AS col2,
11 TO_DATE ('03-01-2009', 'dd-mm-yyyy') AS the_date
12 FROM DUAL
13 UNION ALL
14 SELECT 2222222 AS ID, 'd' AS col2,
15 TO_DATE ('04-01-2009', 'dd-mm-yyyy') AS the_date
16 FROM DUAL
17 UNION ALL
18 SELECT 3333333 AS ID, 'e' AS col2,
19 TO_DATE ('05-01-2009', 'dd-mm-yyyy') AS the_date
20 FROM DUAL
21 UNION ALL
22 SELECT 3333333 AS ID, 'f' AS col2,
23 TO_DATE ('05-01-2009', 'dd-mm-yyyy') AS the_date
24 FROM DUAL)
25 SELECT ID, MAX (the_date)KEEP (DENSE_RANK LAST ORDER BY the_date ),
26 MAX (col2)KEEP (DENSE_RANK LAST ORDER BY the_date )
27 FROM DATA
28 group by id
29 ORDER BY ID;
ID MAX(THE_DA M
1111111 2009-01-01 a
2222222 2009-01-04 d
3333333 2009-01-05 f
SQL> Edited by: Salim Chelabi on 2009-03-05 11:49
Edited by: Salim Chelabi on 2009-03-05 11:50 -
Duplicate rows in over partition by
select * from zzz
id amt
1 10
1 20
2 5
2 6
3 10
select id, sum(amt) over (partition by id order by id) sum from zzz
1 30
1 30
2 11
2 11
3 10Why I'm getting duplicate rows??
Can't use distinct or group by as this is just a small demo and I'll be using my query as part of another complex join.partition by won't filter the results based on group. It shows the exact table rows. The use of this analytical function is you can use the group function without using the group by clause showing all records in the table and group funtion as well. So this is not showing duplicate data but showing the actual data.
If the data is to be filtered based on group, you can use explicitely group by clause.
Hope this helps -
Row Number() over partition by Order by in OBIEE Physical SQL
Hi ,
I created a OBIEE report in Dev using Answers. When I move the same report to Live, the count of rows was more in Live environment when compared to Dev.
The objects count is same in both Dev and Production.
WheniI verified the log file, I found that the Physical SQL in test has
ROW_NUMBER ()
OVER
PARTITION BY c1, c4, c5 order by c1,c4,c5) whereas the physical SQL in Production has
ROW_NUMBER ()
OVER
PARTITION BY c1, c4, c5, c8,c9 order by c1,c4,c5,c8,c9)
How this Partiton is done in OBIEE. I have just copied the report from catalog and moved to production.There is no changes in report.
Whether there are any settings to control it? HOw OBIEE does this Row Number() Partiton ? How can get this similiar to Test?
Please help!
Thanks
JohnnyHi Saichand,
The links were helpful. But i am not getting how it is working in test and not in live.
I found one difference while deploying . The column names of the object both in Test and Production had spaces.For E.g: Full Name
When this column Full Name is pulled to the repsository in test , it automatically put double quotes for the column names in the physical sql when it hits the database.
But, In production , when I pulled the column the report gave error as Invalid Identifier since OBIEE generated column name as Full Name without double quotes.
Then I changed the column in Phyiscal Layer repository by having double Quotes for all columns. Afte that report worked fine.
Whether this has caused any issue in Row Partition.
Is there any setting to have column name in Double Quotes ?
Thanks,
Johnny -
PLSQL does not support 'Sum Over Partition'
I have something (and many obvious syntactical variations) like the following which works great in SQLPLUS but not in PLSQL:
select
table1.aField,
table2.bField,
sum (table1.type) over (partition by type)
from
table1, table2
where
aField = something;
PLSQL does not seem to like the "(" in from of the partition keyword.
I get the following PL/SQL error when I attempt to compile:
4/26 PLS-00103: Encountered the symbol "(" when expecting one of the following:
, fromWhat Oracle version are you running?
Is it Oracle8i?
Begining with Oracle9i, SQL parsers for SQL and PL/SQL were merged togather. Before 9i, many of the new features introduced in SQL were not recognized by the PL/SQL parser.
The following example works as expected on Oracle9i:
SQL> begin
2 for rec in (select deptno, ename, sum(sal) over (partition by deptno)total from scott.emp)
3 loop
4 dbms_output.put_line(rec.ename||' - '||rec.total) ;
5 end loop ;
6 end ;
7 /
CLARK - 8750
KING - 8750
MILLER - 8750
SMITH - 10875
ADAMS - 10875
FORD - 10875
SCOTT - 10875
JONES - 10875
ALLEN - 9400
BLAKE - 9400
MARTIN - 9400
JAMES - 9400
TURNER - 9400
WARD - 9400
PL/SQL procedure successfully completed.
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production
SQL> -
How can use row_number() over partition by plz provide some doc.
row_number() over (partition by)
what is this and how can use it in sql query.
if ur have any documentation of it. plz give...me..
thanx sir
thanx in advance.http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/functions105a.htm
SELECT empno, deptno,
row_number() over (partition by deptno order by empno) rn
from scott.emp
EMPNO DEPTNO RN
7782 10 1
7839 10 2
7934 10 3
7369 20 1
7566 20 2
7788 20 3
7876 20 4
7902 20 5
7499 30 1
7521 30 2
7654 30 3
7698 30 4
7844 30 5
7900 30 6Regards
Dmytro -
Discoverer Plus - Lag / Over / Partition By / Order By (Conditional Syntax)
Good morning everybody
I have created the following syntax in Oracle Discoverer Plus and it works amazingly. However, I have a single problem.
This syntax gives me the comparison of two values (for instance: Jan.2010 values & Feb.2010 values). But it does not give me the value of all of the new records (for instance: if there is no values in Jan.2010, then it will not give me the value of Feb.2010). Hence, my report excludes all of the new records values.
If I am not mistaken, the below formulla will not be changed, but it needs some conditional syntax:
1. Compare syntax: if there is two similar records; and
2. Give the values of all the new records without any change in thier values
*(Amount-LAG(Amount,1)OVER(PARTITION BY "Sequence Number"ORDER BY "Sequence Number ASC))*
Thank very much in advance.
Mr. Zuhair Fardan
Kingdom of Bahrain
Email: [email protected]Zuhair,
change,
(Amount-LAG(Amount,1)OVER(PARTITION BY "Sequence Number"ORDER BY "Sequence Number ASC)){code}
to
{code}
(Amount-LAG(Amount,1,0)OVER(PARTITION BY "Sequence Number" ORDER BY "Sequence Number ASC))Note the extra zero in LAG(Amount,1,0). That's the default return value if nothing is found.
As it is you are subtracting null from the amount and getting null.
Hope that is helpful.
- James
Maybe you are looking for
-
Adobe Photoshop Express Organizer - help manual needed
Please excuse me if I'm posting this request to the wrong forum, but I'm looking for a tutorial on how to use the online Adobe Photoshop Express Organizer, which I access through photoshop.com. I can't locate a tutorial or instructions on it anywhe
-
I am unable to upload raw files from my Canon 7d ii, even after updating elements 12
unable to up load raw files from Canon 7dii
-
Customer Stock / Consignment Stock
Hello, My customer wishes to handle stock for its customer. We don't want to generate any financial posting at all since the cost of good sold has already been triggered at the HQ level. We just want to use SBO as a stock management tool (stock in /
-
Identifying rings and edges with problems
Hi I have new polygon layers that produce a validation error for a polygon of gtype of 2007: 13350 [Element <1>] [Rings 1, 8][Edge <9> in ring <1>][Edge <33> in ring <8>] The error is: ORA-13350: two or more rings of a complex polygon touch Cause: Th
-
Color profiles not shown on colorsync
Hello... I have been looking for a solution to this issue for the last 2 weeks without success... may be somebody knows about it ? Using Mac Os 10.4.11 on an Intel based Mac recently formatted (with the original cd), the color profiles existing on th