ROW_NUMBER() OVER (PARTITION
hi, can anyone explain, especially this part
ROW_NUMBER() OVER (PARTITION BY A.USER_ID ORDER BY A.TNP_TRACK_ID DESC) RN
Thanks
newbie
SELECT A.TNP_TRACK_ID, A.USER_ID, NVL(A.DELETED,0) DELETED, A.CREATE_TIME, A.DELETE_TIME, B.PRODUCT_CODE, C.LOGIN_NAME,
ROW_NUMBER() OVER (PARTITION BY A.USER_ID ORDER BY A.TNP_TRACK_ID DESC) RN
FROM MISPNA.TNP_TRACKABLE_' || TO_CHAR(p_reporting_month, 'YYYYMM') || ' A
JOIN TMP_VRZ_LATEST_SOC B ON A.TNP_TRACK_ID = B.TRACK_ID
JOIN MISPNA.TN_LOGIN C ON A.USER_ID = C.USER_ID
WHERE A.DELETED<>1
Hi,
949523 wrote:
thank you very much, the whole original script is
SELECT TNP_TRACK_ID, USER_ID, DELETED, CREATE_TIME, DELETE_TIME, PRODUCT_CODE, LOGIN_NAME
FROM (
SELECT A.TNP_TRACK_ID, A.USER_ID, NVL(A.DELETED,0) DELETED, A.CREATE_TIME, A.DELETE_TIME, B.PRODUCT_CODE, C.LOGIN_NAME,
ROW_NUMBER() OVER (PARTITION BY A.USER_ID ORDER BY A.TNP_TRACK_ID DESC) RN
FROM MISPNA.TNP_TRACKABLE_' || TO_CHAR(p_reporting_month, 'YYYYMM') || ' A
JOIN TMP_VRZ_LATEST_SOC B ON A.TNP_TRACK_ID = B.TRACK_ID
JOIN MISPNA.TN_LOGIN C ON A.USER_ID = C.USER_ID
WHERE A.DELETED <>1
WHERE RN != 1';I assume the single-quote near the end is just an editing typo.
>
so seems like with specified user_id, it will pick greatest tnp_track_id ? ( as it asks RN=1)That's what it would be doing if the last line read
WHERE rn = 1; for each user_id, that query (with = on the last line) would display all the SELECTed values from the row with the greatest tnp_track_id.
Since you're using != , however, then it's doing just the opposite; it's displaying all rows except the row with the greatest tnp_track_id.
The sub-query is necessary here. All analytic functions, including ROW_NUMBER, are evaluated after the WHERE clause has been applied. To use the results of an analytic function in a WHERE clause, you have to compute the function in a sub-query first.
Edited by: Frank Kulash on Jan 7, 2013 8:08 PM
Just noticed you're saying "WHERE RN != 1" ( not equals)
Similar Messages
-
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? -
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 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 -
Convert SQL Server ROW_NUMBER() OVER(PARTITION BY() Query to Access
Hi,
I am having trouble with converting this SQL Server query to Access. If anyone can give me help I would appreciate it.
SELECT B.AMOUNT_REQUESTED, B.INIT_OFF, B.MBR_NBM, B.STATUS, B.APPLICATION_NBR
FROM
SELECT AMOUNT_REQUESTED, INIT_OFF, MBR_NBM, STATUS, APPLICATION_NBR, ROW_NUMBER() OVER(PARTITION BY MBR_NBM ORDER BY MBR_NBM) RN
FROM LOAN_DATA
WHERE APPLICATION_DATE BETWEEN '20150420' AND '20150425'
) B
WHERE RN = 1
ORDER BY B.MBR_NBMWhile there is no equivalent to ROW_NUMBER(), it appears that you are just wanting the first row of each group, and that CAN be accomplished in Access, but I do wonder why you would WANT to do that in Access if your data is stored in SQL Server. As
Tom indicated a Pass Through query object is likely your best bet -- or a View in SQL Server, then create a Linked Table object that points to it.
To get the first of each group ... which is essentially a TOP n, where n = 1 ... so .. the first thing you will want to indentify is a second field to use as a Key in order to define the "first" row you want in the group. In your SQL
statement, you are ordering my mbr_nbm, so the secondary sort is unknown -- likely predicable, but unknown with out knowledge of the schema ... so, I will provide samples by using APPLICATION_DATE as the sort key.
This one is the "first" of a series with the assumption that the one you want is the one with the "biggest"/"most recent" APPLICATION_DATE.
SELECT vLoanData.AMOUNT_REQUESTED, vLoanData.INIT_OFF, vLoanData.MBR_NBM, vLoanData.STATUS, vLoanData.APPLICATION_NBR
FROM LOAN_DATA As vLoanData
INNER JOIN
(SELECT MBR_NBM, Max(APPLICATION_DATE) As LastAppDate
FROM LOAN_DATA As vLast
GROUP BY MBR_NBM) As vLastApp ON vLoanData.MBR_NBM = vLastApp.MBR_NBM And vLoadData.APPLICATION_DATE = vLastApp.LastAppDate
Or ... the following is a TOP n query where n = 1.
SELECT vLoanData.AMOUNT_REQUESTED, vLoanData.INIT_OFF, vLoanData.MBR_NBM, vLoanData.STATUS, vLoanData.APPLICATION_NBR
FROM LOAN_DATA As vLoanData
WHERE (vLoanData.MBR_NBM & '|' & vLoanData.APPLICATION_DATE)
IN (SELECT TOP 1 (vCorrelated.MBR_NBM & '|' & vCorrelated.APPLICATION_DATE) As Key
FROM LOAN_DATA As vCorrelated
WHERE vCorrelated.MBR_NBM = vLoanData.MBR_NBM
ORDER BY vCorrelated.MBR_NBM, vCorrelated.APPLICATION_DATE DESC)
This second example is not going to win you any points with respect to speed, but is truly a closer model to the TOP N type thing you are doing in SQL Server.
Hope that helps!
Brent Spaulding | Access MVP -
How to implement qualify row_number over(Partition by col order by col) and char2hexint in informatica in a way that is supported by pdo?
Apart from sql overriding or using stored procedure ,is there any other solution?Can rank transformation help here? ....But, I guess rank transformation cannot be pushed down..
help please !Hi 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 -
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 -
Alternative for ROW_NUMBER () OVER.
Hi All,
Is there a way to implement the below logic without using ROW_NUMBER () OVER feature that Oracle provides ?
SELECT
cost_object INTO out_cost_object
FROM
SELECT equip_no,
cost_object,
ROW_NUMBER () OVER (PARTITION BY equip_no, trunc(in_date)
ORDER BY start_date) row_number
FROM escost_object_assign
WHERE equip_no = in_equip
AND in_date between start_date and nvl(end_date,sysdate)
WHERE
a. row_number = 1 ;I want to implement this logic in one of the tool which does not support ROW_NUMBER OVER feature. Please let em know if you need any info.
Thanks and Regards
Nagaraja Akkivalli.Hi,
can you post the structure of escost_object_assign?
Also from your code it seem you are just returning one row (INTO out_cost_object).
But your analytic function seems to be handling more than one rows as you have partition by equip_no, trunc(in_date)
I suppose you can do something like this.
SELECT cost_object
INTO out_cost_object
FROM (SELECT cost_object
FROM escost_object_assign
WHERE equip_no = in_equip
AND in_date BETWEEN start_date AND NVL (end_date, SYSDATE)
ORDER BY start_date
WHERE ROWNUM <= 1;If not, please post some sample data (CREATE TABLE and INSERT statement) and explain exactly the case.
Beside this I have to say that I totally agree with Blu:
You'd be better to change your tool, rather than perfectly acceptable code.A tool should support entirely the database.
Regards.
Al
Edited by: Alberto Faenza on May 14, 2013 12:07 PM -
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 -
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
BharathOWB'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 -
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. -
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.
(^_^) -
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. ;)
Maybe you are looking for
-
My mac book's finder. trash and other things don't work. how can i save all my data even though i cant transfer it all because my disk is full and isn't allowing me to delete stuff? and my midi isn't working
-
How do I make a new finder window open 'inside' my home folder?
In finder I have set new finder windows to open my home folder, however it is actually opening the Users folder. So if I press down, it will select the next user in the list rather than selecting the first folder in my home directory. This doesn't ha
-
Why is connection to iTunes stores so temperamental? For the past 3 days I have been unable to download my newspaper subscription or use my iTunes account as the blue icon pops up and says there is no access and one just has to press OK. I took the i
-
How can I remove my email address from the lock screen?
How do I remove my email address from the lock screen? My dad bought me a new laptop after mine was stolen from my house on New Year's Eve. I'm a little tighter on my security now and when I turn on my laptop the lock screen shows me my name and my e
-
HR-abap friends--reg:SO10 Objects
Hello Friends, i am preparing SO10 objects like appointment letters and promotion letters, here some fields like basic salary means &basic& if coded like its coming i am just confusing how its coming, same way i need syntax for some other fileds hous