Use Aggregate Functions in a View
Is it possible to create a view in SE11 using an aggregate SQL function?
I.e., I want the generated SQL to look like:
CREATE VIEW z_tbl
A,
SUM_AMT
AS SELECT
A,
SUM(AMT)
FROM TBL
GROUP BY A
Thanks for any help.
Executes the Native SQLstatements enclosed between EXEC SQL and ENDEXEC statements. Unlike Open SQLNative SQL statements can address tables that are not declared in theABAP Dictionary.
Example
Creating the Table AVERI_CLNT:
EXEC SQL.
CREATE TABLE AVERI_CLNT (
CLIENT CHAR(3) NOT NULL,
ARG1 CHAR(3) NOT NULL,
ARG2 CHAR(3) NOT NULL,
FUNCTION CHAR(10) NOT NULL,
PRIMARY KEY (CLIENT, ARG1, ARG2)
ENDEXEC.
Similar Messages
-
Facing problem while using aggregate functions.
I am trying to use aggregate functions such as sum, count in my CQL query.
It is not giving me an error but i am unable to get the correct output out of that.
Query is:
<?xml version="1.0" encoding="UTF-8"?>
<wlevs:config xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application"
xmlns:jdbc="http://www.oracle.com/ns/ocep/config/jdbc">
<processor>
<name>APL_EFW_CostEvent_Processor</name>
<rules>
<view id="CostEventView"
schema="eventName eventType eventId opportunityStatusId opportunity_cost APL_Event_Inbound"><![CDATA[
SELECT X.eventName, X.eventType,
X.eventId, X.opportunityStatusId,
X.opportunity_cost,X.APL_Event_Inbound
from APL_EFW_Master_Inbound_Channel
XMLTable (
'/' PASSING BY VALUE APL_EFW_Master_Inbound_Channel.APL_Event_Inbound as "."
COLUMNS
eventId char(256) PATH 'fn:data(Event/EventHeader/eventId)',
eventName char(256) PATH 'fn:data(Event/EventHeader/eventName)',
eventType char(256) PATH 'fn:data(Event/EventHeader/eventType)',
opportunityStatusId char(256) PATH 'fn:data(Event/ApplicationDataArea/opportunity/opportunity_details/opportunity_status)',
opportunity_cost char(256) PATH 'fn:data(Event/ApplicationDataArea/opportunity/opportunity_details/opportunity_cost)',
APL_Event_Inbound xmltype path '/'
) AS X
]>
</view>
<query id="CostEventQuery">
<![CDATA[
SELECT
XMLELEMENT("opportunity",
XMLELEMENT("cost_opportunity",
XMLFOREST(X.opportunity_cost))) as APL_Event_Inbound
FROM CostEventView
MATCH_RECOGNIZE (
MEASURES
A.opportunity_cost as opportunity_cost
PATTERN (B A+) within 30000 milliseconds
DEFINE
A as sum(A.opportunity_cost)> 1000 )
as X
]]>
</query>
</rules>
</processor>
</wlevs:config>
The problem i am getting is when the value is getting compared with the opportunity cost rather than with the sum of oppCost
A as sum(A.opportunityCost)>1000
A as A.opportunityCost >1000
Both the cases are treated as same .It would help if you could provide sample input data and associated output that illustrates the problem
-
Error in using aggregate function in Outer Query in Siebel Analytics
Hi,
When I am using aggregate function in outer query in Siebel Analytics I am facing error.
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 59111] The SQL statement must include a GROUP BY clause. (HY000)
Bellow is the code.
SELECT test1.username saw_0, test1.desg saw_1,COUNT (test2.querydate) saw_2
FROM (SELECT POSITION.CBL username,
POSITION.CBP desg
FROM "CM"
WHERE (POSITION.BPTCD = 'Marketing')
AND (POSITION.EDate =TIMESTAMP '1899-01-01 00:00:00'
) test1,
(SELECT users.UN username,
measures."Query Count" querycount,
measures."Max Total Time" secs,
topic.db dashboardname,
"Query Time".DATE querydate
FROM "Plan"
WHERE (topic."Dashboard Name" IN ('DS'))) test2
WHERE test2.username = LOWER (test1.username)
AND test2.dashboardname = 'DS'
GROUP BY test1.username, test1.desgShould your query be a valid SQL query?
I can't think that the query you have would be valid in a SQL plus window.
Chris -
Using Aggregate function in queries
Hi all,
Please take a look on this query and suggest me why i'm getting the error..
This is my simple query using aggregate function in it..
SELECT T1.NAME, T1.DESCRIPTION, SUM(T2.QUANTITY)
FROM TABLE1 T1, TABLE2 T2
WHERE T1.ID=T2.ID
GROUP BY T1.NAME, T1.DESCRIPTION
Above query added with a sub-query in the select segment..
SELECT T1.NAME, T1.DESCRIPTION, SUM(T2.QUANTITY), (SELECT AVG(T3.PRICE) FROM TABLE1 TT1, TABLE3 T3 WHERE TT1.ID=T3.ID AND TT1.ID=T1.ID) AV_PRICE
FROM TABLE1 T1, TABLE2 T2
WHERE T1.ID=T2.ID
GROUP BY T1.NAME, T1.DESCRIPTION
When i add a sub-query which has aggregate function in it, i'm getting the 'ORA-00979: not a GROUP BY expression' error.What is your DB Version. Your query works without any issue in my DB. I used WITH clause to create the sample data. The query highlighted in BLUE is the actual query.
SQL> select * from v$version where rownum = 1;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
SQL> with table1
2 as
3 (
4 select 1 id, 'karthick' name, 'user name' description from dual
5 ),
6 table2
7 as
8 (
9 select 1 id, 100 quantity from dual
10 ),
11 table3
12 as
13 (
14 select 1 id, 10 price from dual
15 )
16 select t1.name
17 , t1.description
18 , sum(t2.quantity)
19 , (
20 select avg(t3.price)
21 from table1 tt1
22 , table3 t3
23 where tt1.id = t3.id
24 and tt1.id = t1.id
25 ) av_price
26 from table1 t1
27 , table2 t2
28 where t1.id = t2.id
29 group
30 by t1.name
31 , t1.description;
NAME DESCRIPTI SUM(T2.QUANTITY) AV_PRICE
karthick user name 100 10
SQL> -
How to use Aggregate Functions during Top N analysis?
Say i want to find top 5 highest salaries and their totals and average. In that case how to use aggregate functions. Please give me an example on this.
Regards,
Renu
Message was edited by:
user642387Hi,
Yes, you can do that with aggregate functions.
First, do a sub-query to retrieve all the salaries (in descending order), then say "WHERE ROWNUM <= 5" in the main query. Use the aggregate SUM and AVG functions in the main query.
Analytic functions are easier to use for jobs like this, once you get familiar with them. If you're not leaving the field this month, then it's probably worthwhile for you to get familiar with analytic functions. -
Problem while using aggregate functions in EJB QL 2.1
Hai all,
I am using aggregate function as follows
select max(c.id) from customer as c
for this iam selected check box EJB QL 2.1 in persistent.xml
this is validated by nwds, but while deploying server raising error like ejb ql syntax error.
Actually according to EJB QL 2.1 this is a valid query, what i need to do for run this same query .
Anybody please help me in this regard
Regards
SomarajuBeevin
Both two are not even validated,
but with the first one as select max(c.id) from customer as c , in this case it is validated but while deploying it is error as , object must be return
But when i saw the ejb2.1 specification we can write this type of queries also ?
Is it problem with was any thing
Regards
Somaraju -
Problem in using aggregate functions inside case statement
Hi All,
I am facing problem while using aggregate functions inside case statement.
CASE WHEN PSTYPE='S' THEN MAX(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ELSE SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) END,
how can I achieve above requirement ? Con anyone help me.
Thanks and Regards
DGHi All,
Below is my query:
SELECT
CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT
ELSE POS.PACCT || '-' || DECODE(POS.SYSTEMCODE,'GMI1','1', 'GMI2','2', 'GMI3','4', 'GMI4','3', '0') ||POS.PFIRM|| NVL(POS.POFFIC,'000') END,
CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-')
ELSE POS.PFIRM||POS.POFFIC||POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-') END,POS.SYSTEMCODE,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,POS.PEXCH||DECODE(POS.PSUBEX,'<NULL>',''),
POS.PCURSY,
CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) END ,
NVL(POS.PSUBTY,'F') ,POS.PSTRIK,*SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ,SUM(DECODE(POS.PBS,2,ABS(POS.PPRTQ),0))* ,
POS.PCLOSE,SUM(POS.PMKVAL) ,
TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
POS.UBS_ID,POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER ,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,TO_CHAR(POS.BUSINESS_DATE,'YYYYMMDD'),
POS.SOURCE_GMI_LIB,
--DECODE(POS.SYSTEMCODE,'GMI1','euro','GMI2','namr','GMI3','aust','GMI4','asia','POWERBASE','aust','SINACOR','namr',POS.SYSTEMCODE),
DECODE(p_reportid,'RVPOS_SING','euro','RVPOS_AUSTDOM','aust','RVPOS_AUSTEOD','euro','RVPOS_GLBLAPAC','asia','POS_RV_SN','namr','POS_PB','aust',POS.SYSTEMCODE),
POS.RIC,
CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
NVL(C.SSECID,POS.PCUSIP),
NULL,
POS.PYSTMV,
POS.PMINIT,
POS.PEXPDT,
CASE WHEN POS.PSUBTY='S' THEN SUBSTR(C.ZDATA2,77,1) ELSE NULL END,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
FROM POSITIONS_WRK POS LEFT OUTER JOIN
(SELECT * FROM CDS_PRODUCTS CP INNER JOIN FUTURE_MASTER FM ON
(CP.STRXCH=FM.ZEXCH AND CP.SFC=FM.ZFC AND CP.BUSINESS_DATE = FM.BUSINESS_DATE )) C ON POS.PCUSIP = C.SCUSIP
AND NVL(POS.PCUSP2,'X') = NVL(C.SCUSP2,'X')
WHERE
POS.PEXCH NOT IN ('A1','A2','A3','B1','B3','C2','D1','H1','K1','L1','M1','M3','P1','S1')
AND (POS.PSBCUS IS NOT NULL OR POS.PCTYM IS NOT NULL OR POS.PSTYPE ='S')
AND POS.BUSINESS_DATE = run_date_char
GROUP BY
POS.UBS_ID,POS.SYSTEMCODE,POS.RECIPIENTCODE,POS.BUSINESS_DATE,POS.PACCT,POS.PFIRM,POS.POFFIC,POS.PCUSIP,POS.PBS,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,
POS.PEXCH,POS.PSUBEX,POS.PCURSY,
CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) END,
NVL(POS.PSUBTY,'F') ,POS.PSTRIK,POS.PCLOSE,TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,POS.PSUBTY,POS.SOURCE_GMI_LIB,RIC,
CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
NVL(C.SSECID,POS.PCUSIP),
POS.PYSTMV,
POS.PMINIT,
POS.PEXPDT,
CASE WHEN PSUBTY = 'S' THEN SUBSTR(C.ZDATA2,77,1) ELSE NULL END;Now, could you plz help me in replacing the bold text in the query with the requirement.
Thanks and Rgds
DG
Edited by: BluShadow on 16-May-2011 09:39
added {noformat}{noformat} tags. Please read: {message:id=9360002} for details on how to post code/data -
How to use aggregate function with Date
Hi All,
I have a group of date from that is it possible to Max and Min of date.
I have tried like this but its errored out <?MIN (current-group()/CREATION_DATE)?>.
I have also tried like this but it doesnt works
<?xdoxslt:minimum(CREATION_DATE)?>
Is it possible to use aggregate function with date values.
Thanks & Regards
SrikkanthHi KAVI PRIYA,
if date is not in cannonical format, how can we change it in BI publisher, then how to calcualte minimum and as well as maximum.
please advise me,
Thanks,
Sri -
Using aggregate function count
hi experts,
I want to select 2 fields from a table and put into structure (gw_konzs.) and with respect to that i want to use aggregate function count(*) for knowing how many rows has been selected ? and i dont want to use select & endselect
please help regarding this ...........
for example:
select konts ltext from ztab into corresponding fields of gw_konzs.
select count(*) from kna1 into gw_konzs
where konzs = gw_konzs-konzs.
append gw_konzs to gt_konzs
endselect.hi experts,
I want to select 2 fields from a table and put into structure and i want to select based on the where condition i dont want to use select & endselect
please help regarding this ...........
rewarded if useful
for example:
gw_detail & gw_konzs is structure
gt_detail & gt_konzsis internal table
select kunnr name1 from kna1 into corresponding fields of gw_detail where konzs = gw_konzs-konzs.
gw_detail-konzs = gw_konzs-konzs.
append gw_detail-konzs to gt_detail-konzs
endselect. -
How to use aggregate functions into Analytical functions
Can we use aggregate functions into analytical functions?
Please provide one example.
Smiles.HI Learner6
for information:
Aggregate Functions
Analytic Functions
for practic:
ORACLE-BASE - Analytic Functions
Thank you -
Issue in pivot while using aggregate functions
when I use this below query in oracle sql developer
------------->select sum(round(8.08/0.54,2)*30) from dual.
i am getting result as 448.8.it is a correct value
but i use this below queries in pivot as same like above query i am getting result of doubled value 914.4.
PIVOT
SUM(round(ROUND(sellout,2)/6,2)) AS LAST_6_MON_SELL_OUT,
SUM(ROUND(inventory,2)) AS INVENTORY_INTINS_1,
Sum(round(ROUND(inventory,2)/round(ROUND(sellout,2)/6,2),2)*30) As Stockperday
FOR PRODUCT IN (56,78)
actually i am getting value for SUM(round(ROUND(sellout,2)/6,2)) is 0.54,*SUM(ROUND(inventory,2))* is 8.08 i the above query ,but i am getting wrong value for this aggregate function Sum(round(ROUND(inventory,2)/round(ROUND(sellout,2)/6,2),2)30)* as 914.4.but actual value is 448.8
why this problem.can anybody explain me.why this problemTry ur luck in 'sql plsql thread'
PL/SQL -
INDEX on VIEW or TABLE when using CONTAINS function on the VIEW
Hi,
I'm querying a view with a contains function and I'm getting an error:
query: select * from view where contains(name,'jack OR jill')>0
ORA-20000: Oracle text error
DRG-10599 column is not indexed.
From what I gathered you can't create an index on the view, or is that possible afterall (using 10g).
Would it be sufficent to create an index on the column in the table that the view-query is pulling the data from? or can you use the contains funtion on views at all?
Or are there other ways of doing this better?
Thanks,That particular CONTAINS clause will require a domain index on the column, NAME in your case.
You could also do: select * from view where name in ('Jack', 'Jill')
Depending on your need and number of records and other variables, it may be "fastest" to do the text index on the NAME column. If it is a rather small subset of data and performance is not critical then the IN clause should suffice. -
I have to include a function in a view. I want to create a new column in a view which is the output of this function. Can I do it. I am new to using functions..any sample code is appreciated..
Hi,
Yes of corse.
REgards salim.SQL> CREATE OR REPLACE FUNCTION div (sal NUMBER)
2 RETURN REAL
3 IS
4 BEGIN
5 RETURN (sal / 2);
6 END;
7 /
Fonction créée.
SQL> create or replace view v_emp as
2 select empno,ename,sal,div(sal) sal_div
3* from emp_test
SQL> /
Vue créée.
SQL> select * from v_emp;
EMPNO ENAME SAL SAL_DIV
7698 BLAKE 20000 10000
7566 JONES 5950 2975
7699 DAVID 20000 10000
7782 CLARK 20000 10000
7839 KING 10000 5000
7902 FORD 6000 3000
7788 SCOTT 6000 3000
7 ligne(s) sélectionnée(s).
SQL> -
Using analytic function in a view
Hello to all
Sorry If I use this thread
sql not merge using analytic functions
for my question,
From example you write and from Tom explain is not possible create a view on analytic function?
Thanks and sorry againI think what you'll discover is that if you apply the function over the result set, the initial SQL might be quicker,
for example, this is a test I did with a large dictionary view:
select tp.Table_Name
,tp.Partition_Name
from
select tbl.Table_Name as Table_Name
,tbl.Partition_Date as dt
,row_number() over (partition by dtp.table_Name order by dtp.Partition_Name desc) rn
from (
select /*+ all_rows */
dtp.Table_Name
,dtp.Partition_name
from dba_tab_partitions dtp
where dtp.Partition_Name like 'Y____\_Q_\_M__\_D__' escape '\'
and dtp.Table_Owner = 'APPS'
and dtp.Table_name not like '%$%'
and dtp.Table_Name like '%'
) tbl
) tp
where tp.rn = 1
select Table_Name
,Partition_Name
from (
select /*+ all_rows */
dtp.Table_Name
,row_number() over (partition by tbl.table_Name order by tbl.Partition_Name desc) rn
from dba_tab_partitions dtp
where dtp.Partition_Name like 'Y____\_Q_\_M__\_D__' escape '\'
and dtp.Table_Owner = 'APPS'
and dtp.Table_name not like '%$%'
and dtp.Table_Name '%'
) tbl
where rn = 1I found the former to be quicker.
I think ask tom was saying a lot more, but included something similar,
Edited by: bluefrog on Jun 10, 2010 12:48 PM -
Using aggregate function pulls an additional table in join
Hello,
We're facing a wierd scenario whereby using an aggregate function in a report brings an additional table in the query, which should not be included. Please throw some light on this if you have any idea why this would happen. Here are the details
OBIEE version: 10.1.3.4
I pull 2 columns in my report - Col1 (numeric column from Dim A), Col2 (date column from Dim B)
I have already set an implicit fact column in that subject area (Col3 from Fact X)
Now when I run this report, the FROM clause of the sql correctly shows Dim A, Dim B, Fact X
Later, I apply a MAX function on Col2 (date column from Dim B). Ideally, the FROM clause of my sql should still be the same. But here is what happens...
FROM Dim A, Dim B, Fact X, Fact Y (Bridge table).
Fact Y is a bridge table that we are using in this subject area. But there is no reason why this table should get pulled in this query just by using an aggregate function in it.
Your thoughts and insights will be highly appreciated.
Thanks,
VahibDid you apply MAX in the aggregate function section? If that is the case, OBIEE is forced to consider logical table for Dim B as a fact and brings in Y as a way to resolve the join between two facts.
Try setting up a new fact and create MAX column there. See if it resolves that problem or not. You may also want to bring Dim B in the LTS of the main fact and create a column with MAX aggregation. That should work too.
Maybe you are looking for
-
IMac 27" as external under windows
Hello there, I just bought a rMBP and wish to conect it to my 2011 27" iMac, everything works under OS X, but if I try it under windows it won't recognize the iMac at all (this is with thunderbolt). Is there anyway I could use windows 7 (in the macbo
-
Pass word lost , no more security key
I made a big mistake , i could enter my pass word , even i Did not take security key , please help
-
Hi experts, I am currently creating PDF publication based on WebI reports. My client refuse to use the standard access to publication files (right click on publication -> History -> left click on the instance -> access to the PDF) because he thinks t
-
Downloading and installing the adobe reader on a mac
Hi. im having trouble downloading and installing the adobe reader on my mac. can you help me?
-
More junk mail since I've made and applied rules...why?
I was getting 6-8 junk emails a day. It was recommended that I use rules to delete them and prevent them from re-occuring. Now that I have applied the rules I am getting two to three times more junk mail. Why is this happening?