How to use Analytic functions in Forms10g
Hi,
Can we use Analytic function in forms10g like Lead & Lag.
Thanks & Regards,
Use a db view as a data source of your form block ....
Greetings...
Sim
Similar Messages
-
How to use analytic function with aggregate function
hello
can we use analytic function and aggrgate function in same qurey? i tried to find any example on Net but not get any example how both of these function works together. Any link or example plz share with me
Edited by: Oracle Studnet on Nov 15, 2009 10:29 PMselect
t1.region_name,
t2.division_name,
t3.month,
t3.amount mthly_sales,
max(t3.amount) over (partition by t1.region_name, t2.division_name)
max_mthly_sales
from
region t1,
division t2,
sales t3
where
t1.region_id=t3.region_id
and
t2.division_id=t3.division_id
and
t3.year=2004
Source:http://www.orafusion.com/art_anlytc.htm
Here max (aggregate) and over partition by (analytic) function is in same query. So it means we can use aggregate and analytic function in same query and more than one analytic function in same query also.
Hth
Girish Sharma -
How to use analytical functions inside a mapping
Hello everybody. Here Isend you a trick that we are using for two years.
If you want to use a function (for instance :ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...)) inside a mapping you must create an expression with in the INGRP1 the fields you are going to use in the window function and in the OUTGRP1 the function you want. Create an Out -attribute with the expressión and link it to a distinct operator (using a "distinct" you encapsulte the sql and you will be able to use the function inside a filter - in the where clause.). The distinct can eliminate some register (depends on the function). If you validate the expression an error will appear (don't worry about that, the mapping will be ok).
But there is a limitation, you will not be able tou sum over, min over, max over (it detect that they are aggregator functions). Other limitation: the debugger doesn't run with this kind of functions.
Please publish this information on "The Warehouse Builder Utility Exchange". Mi email is [email protected] (if you need more information)It is possible to add SUM, MIN, MAX functions also to OWB releases prior to Paris - You have to put them in double quotes - write "MIN" "MAX" "SUM" etc. The rest of the rules (adding cut-off operator after the expression - as DISTINCT, or UNION ALL) is analogical to with ROW_NUMBER()
That means You can create mapping with following functionality:
SELECT
sum (salary) over (partition by DEPARTMENT) department_salary,
salary,
employee_id,
employee_name
FROM employees_salaries
writing it this way in OWB:
SELECT
"SUM" (salary) over (partition by DEPARTMENT) department_salary,
salary,
employee_id,
employee_name
FROM employees_salaries
Regards,
Martin -
How to use analytical function in this case
SELECT COUNT (rms.status_code) rms_status_count,
rms.status_name rms_status_name,
TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date, 'YYYY') month_year,
MAX (rtd.add_date) date_for_sort
FROM ri_mast_status rms, ri_tran_data rtd
WHERE rtd.status_code = rms.status_code
AND TRUNC (MONTHS_BETWEEN (SYSDATE, rtd.add_date)) < 36
AND NVL (rtd.delete_flg, '0') = '0'
GROUP BY TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date, 'YYYY'),
rms.status_name
ORDER BY MAX (rtd.add_date);
it gives output for the last 3 years based on month and year.r you trying this ?
select *from
select rms.*,
row_number() over(partition by TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date,rms.status_name 'YYYY') order by rtd.add_date) RN,
MAX(rtd.add_date) over(partition by TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date,rms.status_name 'YYYY') order by rtd.add_date) date_for_sort,
COUNT(rms.status_code) over(partition by TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date,rms.status_name 'YYYY') order by rtd.add_date) rms_status_count
FROM ri_mast_status rms, ri_tran_data rtd
WHERE rtd.status_code = rms.status_code
AND TRUNC (MONTHS_BETWEEN (SYSDATE, rtd.add_date)) < 36
AND NVL (rtd.delete_flg, '0') = '0'
where rn=1 -
Using analytic function to get the right output.
Dear all;
I have the following sample date below
create table temp_one
id number(30),
placeid varchar2(400),
issuedate date,
person varchar2(400),
failures number(30),
primary key(id)
insert into temp_one values (1, 'NY', to_date('03/04/2011', 'MM/DD/YYYY'), 'John', 3);
insert into temp_one values (2, 'NY', to_date('03/03/2011', 'MM/DD/YYYY'), 'Adam', 7);
insert into temp_one values (3, 'Mexico', to_date('03/04/2011', 'MM/DD/YYYY'), 'Wendy', 3);
insert into temp_one values (4, 'Mexico', to_date('03/14/2011', 'MM/DD/YYYY'), 'Gerry', 3);
insert into temp_one values (5, 'Mexico', to_date('03/15/2011', 'MM/DD/YYYY'), 'Zick', 9);
insert into temp_one values (6, 'London', to_date('03/16/2011', 'MM/DD/YYYY'), 'Mike', 8);this is output I desire
placeid issueperiod failures
NY 02/28/2011 - 03/06/2011 10
Mexico 02/28/2011 - 03/06/2011 3
Mexico 03/14/2011 - 03/20/2011 12
London 03/14/2011 - 03/20/2011 8All help is appreciated. I will post my query as soon as I am able to think of a good logic for this...hI,
user13328581 wrote:
... Kindly note, I am still learning how to use analytic functions.That doesn't matter; analytic functions won't help in this problem. The aggregate SUM function is all you need.
But what do you need to GROUP BY? What is each row of the result set going to represent? A placeid? Yes, each row will represent only one placedid, but it's going to be divided further. You want a separate row of output for every placeid and week, so you'll want to GROUP BY placeid and week. You don't want to GROUP BY the raw issuedate; that would put March 3 and March 4 into separate groups. And you don't want to GROUP BY failures; that would mean a row with 3 failures could never be in the same group as a row with 9 failures.
This gets the output you posted from the sample data you posted:
SELECT placeid
, TO_CHAR ( TRUNC (issuedate, 'IW')
, 'MM/DD/YYYY'
) || ' - '|| TO_CHAR ( TRUNC (issuedate, 'IW') + 6
, 'MM/DD/YYY'
) AS issueperiod
, SUM (failures) AS sumfailures
FROM temp_one
GROUP BY placeid
, TRUNC (issuedate, 'IW')
;You could use a sub-query to compute TRUNC (issuedate, 'IW') once. The code would be about as complicated, efficiency probably won't improve noticeably, and the the results would be the same. -
How can rewrite the Query using Analytical functions ?
Hi,
I have the SQL script as shown below ,
SELECT cd.cardid, cd.cardno,TT.TRANSACTIONTYPECODE,TT.TRANSACTIONTYPEDESC DESCRIPTION,
SUM (NVL (CASE tt.transactiontypecode
WHEN 'LOAD_ACH'
THEN th.transactionamount
END, 0)
) AS load_ach,
SUM
(NVL (CASE tt.transactiontypecode
WHEN 'FUND_TRANSFER_RECEIVED'
THEN th.transactionamount
END,
0
) AS Transfersin,
( SUM (NVL (CASE tt.transactiontypecode
WHEN 'FTRNS'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'SEND_MONEY'
THEN th.transactionamount
END, 0)
)) AS Transferout,
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_ACH'
THEN th.transactionamount
END, 0)
) AS withdrawal_ach,
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK'
THEN th.transactionamount
END, 0)
) AS withdrawal_check,
( SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK_FEE'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'REJECTED_ACH_LOAD_FEE'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_ACH_REV'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK_REV'
THEN th.transactionamount
END,
0
) +
SUM
(NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK_FEE_REV'
THEN th.transactionamount
END,
0
) +
SUM
(NVL (CASE tt.transactiontypecode
WHEN 'REJECTED_ACH_LOAD_FEE_REV'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'OVERDRAFT_FEE_REV'
THEN th.transactionamount
END, 0)
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'STOP_CHECK_FEE_REV'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'LOAD_ACH_REV'
THEN th.transactionamount
END, 0)
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'OVERDRAFT_FEE'
THEN th.transactionamount
END, 0)
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'STOP_CHECK_FEE'
THEN th.transactionamount
END, 0)
)) AS Fee,
th.transactiondatetime
FROM carddetail cd,
transactionhistory th,
transactiontype tt,
(SELECT rmx_a.cardid, rmx_a.endingbalance prev_balance, rmx_a.NUMBEROFDAYS
FROM rmxactbalreport rmx_a,
(SELECT cardid, MAX (reportdate) reportdate
FROM rmxactbalreport
GROUP BY cardid) rmx_b
WHERE rmx_a.cardid = rmx_b.cardid AND rmx_a.reportdate = rmx_b.reportdate) a
WHERE th.transactiontypeid = tt.transactiontypeid
AND cd.cardid = th.cardid
AND cd.cardtype = 'P'
AND cd.cardid = a.cardid (+)
AND CD.CARDNO = '7116734387812758335'
--AND TT.TRANSACTIONTYPECODE = 'FUND_TRANSFER_RECEIVED'
GROUP BY cd.cardid, cd.cardno, numberofdays,th.transactiondatetime,tt.transactiontypecode,TT.TRANSACTIONTYPEDESC
Ouput of the above query is :
CARDID CARDNO TRANSACTIONTYPECODE DESCRIPTION LOAD_ACH TRANSFERSIN TRANSFEROUT WITHDRAWAL_ACH WITHDRAWAL_CHECK FEE TRANSACTIONDATETIME
6005 7116734387812758335 FUND_TRANSFER_RECEIVED Fund Transfer Received 0 3.75 0 0 0 0 21/09/2007 11:15:38 AM
6005 7116734387812758335 FUND_TRANSFER_RECEIVED Fund Transfer Received 0 272 0 0 0 0 05/10/2007 9:12:37 AM
6005 7116734387812758335 WITHDRAWAL_ACH Withdraw Funds via ACH 0 0 0 300 0 0 24/10/2007 3:43:54 PM
6005 7116734387812758335 SEND_MONEY Fund Transfer Sent 0 0 1 0 0 0 19/09/2007 1:17:48 PM
6005 7116734387812758335 FUND_TRANSFER_RECEIVED Fund Transfer Received 0 1 0 0 0 0 18/09/2007 7:25:23 PM
6005 7116734387812758335 LOAD_ACH Prepaid Deposit via ACH 300 0 0 0 0 0 02/10/2007 3:00:00 AM
I want the output like for Load_ACH there should be one record etc.,
Can any one help me , how can i rewrite the above query using analytical functions .,
SekharNot sure of your requirements but this mayhelp reduce your code;
<untested>
SUM (
CASE
WHEN tt.transactiontypecode IN
('WITHDRAWAL_CHECK_FEE', 'REJECTED_ACH_LOAD_FEE', 'WITHDRAWAL_ACH_REV', 'WITHDRAWAL_CHECK_REV',
'WITHDRAWAL_CHECK_FEE_REV', 'REJECTED_ACH_LOAD_FEE_REV', 'OVERDRAFT_FEE_REV','STOP_CHECK_FEE_REV',
'LOAD_ACH_REV', 'OVERDRAFT_FEE', 'STOP_CHECK_FEE')
THEN th.transactionamount
ELSE 0) feeAlso, you might want to edit your post and use [pre] and [/pre] tags around your code for formatting. -
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. -
Using analytical function - value with highest count
Hi
i have this table below
CREATE TABLE table1
( cust_name VARCHAR2 (10)
, txn_id NUMBER
, txn_date DATE
, country VARCHAR2 (10)
, flag number
, CONSTRAINT key1 UNIQUE (cust_name, txn_id)
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9870,TO_DATE ('15-Jan-2011', 'DD-Mon-YYYY'), 'Iran', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9871,TO_DATE ('16-Jan-2011', 'DD-Mon-YYYY'), 'China', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9872,TO_DATE ('17-Jan-2011', 'DD-Mon-YYYY'), 'China', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9873,TO_DATE ('18-Jan-2011', 'DD-Mon-YYYY'), 'Japan', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9874,TO_DATE ('19-Jan-2011', 'DD-Mon-YYYY'), 'Japan', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9875,TO_DATE ('20-Jan-2011', 'DD-Mon-YYYY'), 'Russia', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9877,TO_DATE ('22-Jan-2011', 'DD-Mon-YYYY'), 'China', 0);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9878,TO_DATE ('26-Jan-2011', 'DD-Mon-YYYY'), 'Korea', 0);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9811,TO_DATE ('17-Jan-2011', 'DD-Mon-YYYY'), 'China', 0);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9854,TO_DATE ('13-Jan-2011', 'DD-Mon-YYYY'), 'Taiwan', 0);
The requirement is to create an additional column in the resultset with country name where the customer has done the maximum number of transactions
(with transaction flag 1). In case we have two or more countries tied with the same count, then we need to select the country (among the tied ones)
where the customer has done the last transaction (with transaction flag 1)
e.g. The count is 2 for both 'China' and 'Japan' for transaction flag 1 ,and the latest transaction is for 'Japan'. So the new column should contain 'Japan'
CUST_NAME TXN_ID TXN_DATE COUNTRY FLAG country_1
Peter 9811 17-JAN-11 China 0 Japan
Peter 9854 13-JAN-11 Taiwan 0 Japan
Peter 9870 15-JAN-11 Iran 1 Japan
Peter 9871 16-JAN-11 China 1 Japan
Peter 9872 17-JAN-11 China 1 Japan
Peter 9873 18-JAN-11 Japan 1 Japan
Peter 9874 19-JAN-11 Japan 1 Japan
Peter 9875 20-JAN-11 Russia 1 Japan
Peter 9877 22-JAN-11 China 0 Japan
Peter 9878 26-JAN-11 Korea 0 Japan
Please let me know how to accomplish this using analytical functions
Thanks
-LearnsequelDoes this work (not spent much time checking it)?
WITH ana AS (
SELECT cust_name, txn_id, txn_date, country, flag,
Sum (flag)
OVER (PARTITION BY cust_name, country) n_trx,
Max (CASE WHEN flag = 1 THEN txn_date END)
OVER (PARTITION BY cust_name, country) l_trx
FROM cnt_trx
SELECT cust_name, txn_id, txn_date, country, flag,
First_Value (country) OVER (PARTITION BY cust_name ORDER BY n_trx DESC, l_trx DESC) top_cnt
FROM ana
CUST_NAME TXN_ID TXN_DATE COUNTRY FLAG TOP_CNT
Fred 9875 20-JAN-11 Russia 1 Russia
Fred 9874 19-JAN-11 Japan 1 Russia
Peter 9873 18-JAN-11 Japan 1 Japan
Peter 9874 19-JAN-11 Japan 1 Japan
Peter 9872 17-JAN-11 China 1 Japan
Peter 9871 16-JAN-11 China 1 Japan
Peter 9811 17-JAN-11 China 0 Japan
Peter 9877 22-JAN-11 China 0 Japan
Peter 9875 20-JAN-11 Russia 1 Japan
Peter 9870 15-JAN-11 Iran 1 Japan
Peter 9878 26-JAN-11 Korea 0 Japan
Peter 9854 13-JAN-11 Taiwan 0 Japan
12 rows selected. -
Should I use Analytic functions ?
Hello,
I have a table rci_dates with the following structure (rci_id,visit_id,rci_name,rci_date).
A sample of data in this table is as given below.
1,101,'FIRST VISIT', '2010-MAY-01',
2,101,'FIRST VISIT', '2010-MAY-01'
3,101,'FIRST VISIT', '2010-MAY-01'
4,101,'FIRST VISIT', '2010-MAY-01'
5,102,'SECOND VISIT', '2010-JUN-01',
6,102,'SECOND VISIT', '2010-JUN-01'
7,102,'SECOND VISIT', '2010-JUN-01'
8,102,'SECOND VISIT', '2010-JUL-01'
I want to write a query which returns me the records which are similar to the record with rc_id =8 since the rci_date is different within the visit_id 102. Where as in Visit_id 101 the rci_dates are all same so it should not be displayed in the output returned by my query.
How can I do this ? Should I be using analytic functions. Can someone please let me know.
Thanksok i have created the table and inserted the data. but it appears that the data are the output you are expecting, they all the same visit_id.
SQL> CREATE TABLE RCI
2 (RCI_ID NUMBER(10) NOT NULL,
3 VISIT_ID NUMBER(10) NOT NULL,
4 RCI_NAME VARCHAR2(20 BYTE) NOT NULL,
5 DCI_DATE VARCHAR2(8 BYTE));
Table created
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14876540, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14876640, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14876740, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14876840, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14876940, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877040, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877140, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877240, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877240, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877640, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877740, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877840, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877940, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878040, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878140, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878240, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878340, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878440, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878540, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877640, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14877740, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878340, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878540, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 17418240, 12140, 'SCREENING', '20000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 17418340, 12140, 'SCREENING', '20000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 17418440, 12140, 'SCREENING', '20000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14878240, 12140, 'SCREENING', '20000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 18790240, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 21724540, 12140, 'SCREENING', '19000101');
1 row inserted
SQL> INSERT INTO RCI ( RCI_ID, VISIT_ID, RCI_NAME, DCI_DATE ) VALUES ( 14876540, 12140, 'SCREENING', '20091015');
1 row inserted
SQL> commit;
Commit complete
SQL> select * from rci;
RCI_ID VISIT_ID RCI_NAME DCI_DATE
14876540 12140 SCREENING 19000101
14876640 12140 SCREENING 19000101
14876740 12140 SCREENING 19000101
14876840 12140 SCREENING 19000101
14876940 12140 SCREENING 19000101
14877040 12140 SCREENING 19000101
14877140 12140 SCREENING 19000101
14877240 12140 SCREENING 19000101
14877240 12140 SCREENING 19000101
14877640 12140 SCREENING 19000101
14877740 12140 SCREENING 19000101
14877840 12140 SCREENING 19000101
14877940 12140 SCREENING 19000101
14878040 12140 SCREENING 19000101
14878140 12140 SCREENING 19000101
14878240 12140 SCREENING 19000101
14878340 12140 SCREENING 19000101
14878440 12140 SCREENING 19000101
14878540 12140 SCREENING 19000101
14877640 12140 SCREENING 19000101
14877740 12140 SCREENING 19000101
14878340 12140 SCREENING 19000101
14878540 12140 SCREENING 19000101
17418240 12140 SCREENING 20000101
17418340 12140 SCREENING 20000101
17418440 12140 SCREENING 20000101
14878240 12140 SCREENING 20000101
18790240 12140 SCREENING 19000101
21724540 12140 SCREENING 19000101
14876540 12140 SCREENING 20091015
30 rows selected
SQL> -- using the sample similar code that i have previously posted it returned all the rows.
SQL> select rci.*
2 from rci
3 where rci.visit_id in (select r1.visit_id
4 from (select rci.visit_id,
5 count(*) over (partition by rci.visit_id, rci.dci_date order by rci.visit_id) rn
6 from rci) r1
7 where r1.rn = 1)
8 order by rci.rci_id;
RCI_ID VISIT_ID RCI_NAME DCI_DATE
14876540 12140 SCREENING 20091015
14876540 12140 SCREENING 19000101
14876640 12140 SCREENING 19000101
14876740 12140 SCREENING 19000101
14876840 12140 SCREENING 19000101
14876940 12140 SCREENING 19000101
14877040 12140 SCREENING 19000101
14877140 12140 SCREENING 19000101
14877240 12140 SCREENING 19000101
14877240 12140 SCREENING 19000101
14877640 12140 SCREENING 19000101
14877640 12140 SCREENING 19000101
14877740 12140 SCREENING 19000101
14877740 12140 SCREENING 19000101
14877840 12140 SCREENING 19000101
14877940 12140 SCREENING 19000101
14878040 12140 SCREENING 19000101
14878140 12140 SCREENING 19000101
14878240 12140 SCREENING 19000101
14878240 12140 SCREENING 20000101
14878340 12140 SCREENING 19000101
14878340 12140 SCREENING 19000101
14878440 12140 SCREENING 19000101
14878540 12140 SCREENING 19000101
14878540 12140 SCREENING 19000101
17418240 12140 SCREENING 20000101
17418340 12140 SCREENING 20000101
17418440 12140 SCREENING 20000101
18790240 12140 SCREENING 19000101
21724540 12140 SCREENING 19000101
30 rows selected
SQL> just as what frank have said it will be helpful if you post a sample output based on the original posting, that is in the first posting you have. -
Hi all,
I want an help in creating my SQL query to extract the data described below:
I have one table example test containing data like below:
ID Desc Status
1 T1 DEACTIVE
2 T2 ACTIVE
3 T3 SUCCESS
4 T4 DEACTIVE
The thing i want to do is selecting all lines with ACTIVE status in this table but is there is no ACTIVE status, my query will give me the last line with DEACTIVE status.
Can I do this in one query by using analytical function for example, if yes can yiu help me on thaht query.
regards,
RaluceHi, Raluce,
Here's one way to do that:
WITH got_r_num AS
SELECT deptno, ename, job, hiredate
, ROW_NUMBER () OVER ( PARTITION BY deptno
ORDER BY job
, hiredate DESC
) AS r_num
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK')
SELECT deptno, ename, job, hiredate
FROM got_r_num
WHERE job = 'ANALYST'
OR r_num = 1
ORDER BY deptno
Since I don't have a sample version of your table, I used scott.emp to illustrate.
Output:
DEPTNO ENAME JOB HIREDATE
10 MILLER CLERK 23-JAN-82
20 SCOTT ANALYST 19-APR-87
20 FORD ANALYST 03-DEC-81
30 JAMES CLERK 03-DEC-81
This query finds all ANALYSTs in each department, regardless of how many there are. (Deptno 20 happens to have 2 ANALYSTs.) If there is no ANALYST in a department, then the most recently hired CLERK is included. (Deptnos 10 and 30 don't have any ANALYSTs.)
This "partitions", or sub-divides, the table into separate units, one for each department. In the problem you posted, it looks like you want to operate in the entire table, without sub-dividing it in any way. To do that, just omit the PARTITION BY clause in the analytic ROW_NUMBER function, like this:
WITH got_r_num AS
SELECT deptno, ename, job, hiredate
, ROW_NUMBER () OVER ( -- PARTITION BY deptno
ORDER BY job
, hiredate DESC
) AS r_num
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK')
SELECT deptno, ename, job, hiredate
FROM got_r_num
WHERE job = 'ANALYST'
OR r_num = 1
ORDER BY deptno -
How to use read_text function module
Hi how to use read_text function module to read purchase order header text .what are all tht things to pass in ID,Name and Object
thanks,
MaheDear,
Use below code.
DATA:IT_LINE LIKE TLINE OCCURS 0 WITH HEADER LINE,
V_TDNAME LIKE THEAD-TDNAME.
V_TDNAME = PO_NUMBER.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
ID = 'F01'
LANGUAGE = 'EN'
NAME = V_TDNAME
OBJECT = 'EKKO'
TABLES
LINES = IT_LINE.
Thanks and Regards, -
How to use standard function keys as custom keys
how to use standard function keys as custom keys.
i have encountered that problem while developing a screen, there i'm supposed to use standard function key F2 ( which actually meant for choose) for clearing the screen fields where the cursor is present and f1 for saving data that entered in screen fields, etc...
kindly help me out.Hi ,
Solution to use SAP reserve function keys F1 .. F4 (mostly this requirement comes up for RF screens) can be acheived by assigning your new Function code using the Menu path Utilities --> F key Consistency in the Menu Painter (SE41) . Once you assign your cutom function code to the standard Fn keys the only remaining step is to make sure that you set a curson on any of the field on sceen by using the Key Word "SET CURSOR" .
If you dont use the key word SET CURSOR in the PBO of the screen then you might not see any response for F4.
Thanks -
How to use SQL functions in the queries
hey guys i wanna know how to use SQL functions in the queries is it possible or not .
Hi,
Wat exactly that set values are?
those from sql query?
How to use count():
The COUNT() function returns the number of rows that matches a specified criteria.
SQL COUNT(column_name) Syntax
The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
SELECT COUNT(column_name) FROM table_name
SQL COUNT(*) Syntax
The COUNT(*) function returns the number of records in a table:
SELECT COUNT(*) FROM table_name
SQL COUNT(DISTINCT column_name) Syntax
The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
SELECT COUNT(DISTINCT column_name) FROM table_name
The IN function helps reduce the need to use multiple OR conditions.
The syntax for the IN function is:
SELECT columns
FROM tables
WHERE column1 in (value1, value2, .... value_n); -
How to use this function in crm5.2 - /CEM/ENT_IMPORT_DATAFROMEXCEL
i am having a problem regarding how to use this function to import values from an excel sheet.
in call funtion what to specify at place of ct_ent_action = ?
CALL FUNCTION '/CEM/ENT_IMPORT_DATAFROMEXCEL'
CHANGING
CT_ENT_ACTION =
EXCEPTIONS
FILE_ERROR = 1
IMPORT_ERROR = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.Hi
The use of Standard Parner functions are as follows:
1. Ordering Address (OA): The PO will be sent this vendor and not the main vendor.
2. Goods Supplier (WL): In case of return deliveries, Goods will be returned to thsi vendor's address
3. Invoicing party (RS): The payment will be made to this vendor.
Hope this clarifies.
Thansk -
How to use these function modules
Hi all,
can anyone help that how to use these Function modules to update the status of a task, what are all the inputs i required to proceed
1. FC_USER_AUTHORITY_CHECK
<b>2. FC_USER_STATUS_CHECK
3. FC_USER_STATUS_UPDATE</b>
4. FC_USER_GET_CACTI
5. FC_USER_CHECK_FOR_OUTPUT
Thanks in Advance
GaneshHi Rob,
thanks for ur reply,
but they are not clear what they are meant to be, I understood there are some flags needed to run the Function Modules 2 & 3 which are in bold...
but how do i populate them.. i am not getting that..
thanks
ganesh
Maybe you are looking for
-
How to add a new item-position to salesorder in dialog
Dear all, i have a request to add a new item position to an existing sales order in dialog. The information I have are material number and quanity. After adding these infos the system should work like the user has added the line manually (Entered Mat
-
When i plug in my ZEN Touch 20 gig, with updates firmware, the USB screen "Docked" will flash very quickly, The noise comes on my computer, and i go to back up my media, It won't stay docked, I have jiggled the cable, and plugged it in all different
-
SQL Server 2008r2 issue for w8.1
Hi, I am getting sql server 2008r2 compatibility issue for w8.1 whenever I try to installed it.Please check the attached screen shoot given bellow
-
KeyNote installlation problem on iPad 2
I bought keynote application in my iPad 2 but the installation fails. I have tried to install again pressing the install button but when the installación begin, it fails and exit. I don't see the keynote icon in the iPad. Doe anyone know how can i pr
-
CUBE - Are different pay as you grow license types stackable?
Hi. I'd like to know if Redundant licences are stackable with single use licenses. Perhaps someone could kindly assist. Do I need to buy enough RED licenses for the total session count, thus wasting the bundled licenses that are supplied with the dev