How to achive this using analytical function-- please help
version 10g.
this code works just fine with my requirement. i am tyring to learn analytical functions and implement that in the below query. i tried using row_number ,
but i could nt achive the desired results. please give me some ideas.
SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
f.prvdr_lctn_iid
FROM tax_entity_detail c,
provider_detail e,
provider_location f,
provider_location_detail pld
WHERE c.tax_entity_sid = e.tax_entity_sid
AND e.prvdr_sid = f.prvdr_sid
AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
AND c.oprtnl_flag = 'A'
AND c.status_cid = 2
AND e.oprtnl_flag = 'A'
AND e.status_cid = 2
AND (c.from_date) =
(SELECT MAX (c1.from_date)
FROM tax_entity_detail c1
WHERE c1.tax_entity_sid = c.tax_entity_sid
AND c1.oprtnl_flag = 'A'
AND c1.status_cid = 2)
AND (e.from_date) =
(SELECT MAX (c1.from_date)
FROM provider_detail c1
WHERE c1.prvdr_sid = e.prvdr_sid
AND c1.oprtnl_flag = 'A'
AND c1.status_cid = 2)
AND pld.oprtnl_flag = 'A'
AND pld.status_cid = 2
AND (pld.from_date) =
(SELECT MAX (a1.from_date)
FROM provider_location_detail a1
WHERE a1.prvdr_lctn_iid = pld.prvdr_lctn_iid
AND a1.oprtnl_flag = 'A'
AND a1.status_cid = 2)thanks
Edited by: new learner on May 24, 2010 7:53 AM
Edited by: new learner on May 24, 2010 10:50 AM
May be like this not tested...
select *
from
SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
f.prvdr_lctn_iid, c.from_date as c_from_date, max(c.from_date) over(partition by c.tax_entity_sid) as max_c_from_date,
e.from_date as e_from_date, max(e.from_date) over(partition by e.prvdr_sid) as max_e_from_date,
pld.from_date as pld_from_date, max(pld.from_date) over(partition by pld.prvdr_lctn_iid) as max_pld_from_date
FROM tax_entity_detail c,
provider_detail e,
provider_location f,
provider_location_detail pld
WHERE c.tax_entity_sid = e.tax_entity_sid
AND e.prvdr_sid = f.prvdr_sid
AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
AND c.oprtnl_flag = 'A'
AND c.status_cid = 2
AND e.oprtnl_flag = 'A'
AND e.status_cid = 2
AND pld.oprtnl_flag = 'A'
AND pld.status_cid = 2
)X
where c_from_date=max_c_from_date AND e_from_date =max_e_from_date AND
pld_from_date=max_pld_from_date
Similar Messages
-
How to achive using analytical functions -- please help
oracle version : 10g
-- 999 means ALL values for that key
with input_parameters as (select 10 filter_key , '10ACCC' filter_value from dual union all
select 50 filter_key ,'10ACCC0001' filter_value from dual union all
select 60 filter_key , 'PIP' filter_value from dual union all
select 70 filter_key , 'A' filter_value from dual) select * from input_parameters;
with profile_search as(
select 100 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 100 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
select 100 profile_id , 50 filter_key , '10ACCC0002' filter_value from dual union all
select 100 profile_id , 60 filter_key , '999' filter_value from dual union all
select 100 profile_id , 70 filter_key , '999' filter_value from dual union all
select 101 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 101 profile_id , 50 filter_key , '10ACCC001' filter_value from dual union all
select 101 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
select 101 profile_id , 70 filter_key , '999' filter_value from dual union all
select 102 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 102 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
select 102 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
select 102 profile_id , 70 filter_key , 'A' filter_value from dual)
select filter_key , wm_concat(filter_value) from profile_search group by profile_id, filter_key ;
need to identify profile that matches input parameters
102 is first match because it matches exactly
101 is second match because 999 can match any value
100 is third match KEY 70 HAS HIGHEST WEIGHT,
KEY 60 has next highest weight and KEY 50 has next highest weight
results required :
profile_id : 102
Edited by: devarade on Jan 19, 2010 8:01 PM
Edited by: devarade on Jan 19, 2010 8:01 PMI assume there is a typo in your sample:
select 101 profile_id , 50 filter_key , '10ACCC001' filter_value from dual union allshould be:
select 101 profile_id , 50 filter_key , '10ACCC00<font color=red size=2>0</font>1' filter_value from dual union allThen:
with input_parameters as (
select 10 filter_key , '10ACCC' filter_value from dual union all
select 50 filter_key ,'10ACCC0001' filter_value from dual union all
select 60 filter_key , 'PIP' filter_value from dual union all
select 70 filter_key , 'A' filter_value from dual
profile_search as(
select 100 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 100 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
select 100 profile_id , 50 filter_key , '10ACCC0002' filter_value from dual union all
select 100 profile_id , 60 filter_key , '999' filter_value from dual union all
select 100 profile_id , 70 filter_key , '999' filter_value from dual union all
select 101 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 101 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
select 101 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
select 101 profile_id , 70 filter_key , '999' filter_value from dual union all
select 102 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 102 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
select 102 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
select 102 profile_id , 70 filter_key , 'A' filter_value from dual
select profile_id,
sum(direct_match_cnt) || ' direct matches out of ' || (select count(*) from input_parameters) match
from (
select b.profile_id,
b.filter_key,
b.filter_value,
sum(case when b.filter_value = a.filter_value then 1 else 0 end) direct_match_cnt
from input_parameters a,
profile_search b
where b.filter_key = a.filter_key
and (b.filter_value = a.filter_value or b.filter_value = '999')
group by b.profile_id,
b.filter_key,
b.filter_value
) x
group by profile_id
having count(*) = (select count(*) from input_parameters)
order by sum(direct_match_cnt) desc
PROFILE_ID MATCH
102 4 direct matches out of 4
101 3 direct matches out of 4
100 2 direct matches out of 4
SQL> SY. -
How the achive this using the function module SO_NEW_DOCUMENT_SEND_API1
I want to format the body of the mail like this.How to maintian proper spacing between the fields.kindly suggest.
It may contain multiple line items also.
SC Number | SC Item Number | SC Item Qty | PO Number | PO Item Price
SC Name | SC Item Text | SC Item Price | PO Item | Invoice Item Price
<SC_NUMBER> <SC_ITEM> <SC_QTY> <PO_NUMBER> <PO_PRICE>
<SC_NAME> <SC_ITEM_TEXT> <SC_PR> <PO_ITEM> <IV_PRICE>Hi,
You can do with SOFM method select over there Excel Sheet as same format you can select all fields respectively so in the output in an attachment you will get the values as you like that format in the same way multiple line items also you can retrive data in Excel sheet attachement, then using this FM you can send mail with this attachement.
Thanks and regards,
Prabhakar Dharmala -
How to achive this using servlet
hi I am new to this technology... My requirement is , First I have to check whether that rebate_sku_num exists in the database or not.. If exits i need to update the row.. If now I have to insert the new row with values.. How to achive this..
my screen contains 7 rows... in will increase.. for every submit.. i have to check with the database.. whether the rebate_sku_num exists or not.. help me out.. here is my code.. i am not sure how to format my code.. in future i will do it...
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.SingleThreadModel;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import java.io.IOException;
import java.sql.ResultSet;
import java.io.*;
import java.util.*;
import java.util.Date;
import java.text.*;
public class AddRebate extends HttpServlet implements SingleThreadModel {
public void init(ServletConfig servletconfig) throws ServletException {
super.init(servletconfig);
public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException {
HttpSession session;
session = httpservletrequest.getSession(true);
String user_name;
String divisionCode;
String rebate_sku_num[];
String selectedMonth;
String amount[];
String message = "";
String Query="";
String RebateId="";
boolean flag = true;
// from here
Calendar todaysdate = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy HH:MM:SS");
System.out.println("today's date: " + sdf.format(todaysdate.getTime()));
String entryDate = sdf.format(todaysdate.getTime());
String entryDate1 = sdf1.format(todaysdate.getTime());
System.out.println("entering date is " +entryDate) ;
System.out.println("entering date is " +entryDate1) ;
// to here
user_name = (String) session.getAttribute("user_name");
divisionCode = (String) session.getAttribute("division_code");
selectedMonth = httpservletrequest.getParameter("selectedMonth");
rebate_sku_num = httpservletrequest.getParameterValues("rebateId");
amount = httpservletrequest.getParameterValues("amount");
System.out.println("AddRebate : doPost() : selectedMonth = " + selectedMonth);
System.out.println("AddRebate : doPost() : rebate_sku_num = " + rebate_sku_num);
System.out.println("AddRebate : doPost() : amount = " + amount);
// from here
flag = true;
for (int z = 0; z < rebate_sku_num.length && flag; z++) {
try {
flag=false;
String s = "select REBATE_SKU_NUM from EASMSA_REBATE_SKU_DETAILS_TB where REBATE_SKU_NUM ='" + rebate_sku_num[z] + "'";
System.out.println("AdjustmentServlet : doGet() : checking sku validity query = " + s);
ResultSet resultset = DatabaseConnection.executeQuery(s);
if (resultset != null) {
while (resultset.next()) {
RebateId = resultset.getString("REBATE_SKU_NUM");
flag = true;
if ((rebate_sku_num[z] != RebateId)) {
System.out.println("get the values" +rebate_sku_num);
System.out.println("get the values" + RebateId);
Query = "INSERT INTO EASMSA_REBATE_SKU_DETAILS_TB " +
"( REBATE_SKU_NUM, REBATE_DATE, REBATE_AMT, CREATED_BY," +
"CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE ) VALUES (" +
"'" + rebate_sku_num[z] + "', " +
"TO_Date( '" + "30/" + selectedMonth + "', 'dd/MM/YYYY HH:MI:SS AM'), " +
"'" + amount[z] + "' , '" + user_name + "'" +
", TO_Date( '" + entryDate + "', 'MM/dd/YYYY HH:MI:SS AM')" +
", '" + user_name + "'," +
" TO_Date( '" + entryDate + "', 'MM/dd/YYYY HH:MI:SS AM'))";
System.out.println("query is executed" +Query);
}else if ((rebate_sku_num[z] == RebateId )){
Query = "update EASMSA_REBATE_SKU_DETAILS_TB set REBATE_AMT=" + amount[z] + " where REBATE_SKU_NUM='" + rebate_sku_num[z] + "'";
System.out.println("query is executed for updation" +Query);
} else {
System.out.println("AdjustmentServlet : doGet() : checking for sku validity : resultset null");
// message = "SKU '" + sku[z] + "' of customer '" + customer[z] + "' and location '" + location[z] + "' is not valid.";
message = "SKU '" + rebate_sku_num[z] + "' is not valid.";
flag = false;
} catch (Exception exception1) {
System.out.println("AdjustmentServlet : doGet() : exception in checking validity of SKU");
exception1.printStackTrace();
// message = "SKU '" + sku[z] + "' of customer '" + customer[z] + "' and location '" + location[z] + "' is not valid.";
message = "SKU '" + rebate_sku_num[z] + "' is not valid.";
flag = false;
try {
if (DatabaseConnection.executeUpdate(Query) == 0) {
System.out.println(" AddRebate : doPost() : rollback: error in executing update query= " + Query);
DatabaseConnection.rollBack();
message = "Some problem in updating transactions. Please try again later.";
flag = false;
// break;
} else {
System.out.println("AddRebate : doPost() : update sucessfull");
message = "Rebate Transactions has been updated.";
flag = true;
} catch (Exception ex) {
System.out.println("AddRebate : doPost() : exception in update query");
message = "Some problem in updating transactions. Please try again later.";
flag = false;
ex.printStackTrace();
session.setAttribute("message", message);
httpservletresponse.sendRedirect("Welcome1.jsp?s=y");
return;Oh and you can give me the dukes for helping you here:
http://forum.java.sun.com/thread.jsp?forum=45&thread=475828&tstart=0&trange=15 -
How to program this in java? Please help
How to program this in java?
please explain steps, it has to come out like this:
example
input: 3b1w3b
output:
BBBWBBBimport java.io.*;
public class Test {
static java.io.PrintStream o = java.lang.System.out;
public static void main(String[] args)throws Exception {
BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter plot for printing: ");
String s = BR.readLine();
char[] cs = s.toLowerCase().toCharArray();
for(int i=0, j=0; i < cs.length-0x1; i+=0x2, j=0)
while(j++ < (int)(cs[i]-0x30))
o.print((char)(cs[i+0x1]-0x20));
I tried changeing it to this so I can enter my own string, but I want to change it some more so that it can enter multiple input separated by space, so that it can form a sort of picture line by line. I tried using tolkenizer but I get errors. I dont know how to use tolkenizer properly can anyone please TEACH. you dont have to tell how or give me the code if you dont want to. yes I know Im a noob and I dont know java as good as everyone here, If everyone thinks I don't deserve help then DON'T help, I'm just trying to learn programming -
How to remove this background from Photoshop please help?
This is what I have. http://img89.imageshack.us/img89/1681/xdzj.png
CS6
I used the magnetic and polyganol lasso tool to remove sections, after I drew a section, I pressed enter and then backspace, which made the section turn gray. But now it's just gray, on the same layer, and I can't do anything about it. I wanted an empty background under the image.
I can't use the magic selection tool because it DOES NOT select around the image properly (it selects INSIDE of the image) not where I cropped it out. And the magic selection tool is crappy. It leaves zig zagged white spots so why would I use that. I cropped the entire thing out, and now I can't even see it without the background? What the F**king* F**k?You are indeed looking at the transparency, there is nothing below that layer. Your Layer panel only shows your one layer.
The circles you created (with the eraser, I guess?) show the checkered scheme that denotes the transparency.
Without knowing what exact version of Photoshop, of your OS and platform (the screen shot shows Windows) I can't even begin to guess how you got the gray in there: some option in a tool somewhere, the paint bucket even…?
You can embed images in your posts by using the little camera icon in the Reply Editor of the forum's web interface. -
How to write this query.. Please Help
Hello Guys,
I have a table that contains all possible leave types, it is a look up table. Table name is Att_Leave_Types and data in the table is:
Leavetype_ID Leavetype_Desc
1 Annaul
2 Sick
3 Casual
4 Long
5 Maternity
Now, another table Att_Emp_Leaves Contains leaves of an employee
Columns and values are
Emp_ID leave_date levetype_id
14210 28-AUG-06 2
14210 30-AUG-06 3
14210 12-JUL-06 1
14210 13-JUL-06 1
14210 14-JUL-06 1
6902 27-AUG-06 2
6902 30-AUG-06 3
Now i want to get the following result from the query:
Group by month and year
list all leavetypes and leaves employee have availved, if no leavetype availved then the result must show 0 for the leavetype. calculate leaves for a month based on leavetype ID.
This result will help you clear what i result i want by my query.
MON_YYYY employee_id leavetype_id number_of_leaves
JUL-2006 14210 1 3
JUL-2006 14210 2 0
JUL-2006 14210 3 0
JUL-2006 14210 4 0
JU:-2006 14210 5 0
AUG-2006 14210 1 0
AUG-2006 14210 2 1
AUG-2006 14210 3 1
AUG-2006 14210 4 0
AUG-2006 14210 5 0
AUG-2006 6902 1 0
AUG-2006 6902 2 1
AUG-2006 6902 3 1
AUG-2006 6902 4 0
AUG-2006 6902 5 0
Please guide me and help me, its very urgent.
I will be thankful to you.
Regards,
Imran BaigHere we are:
DROP TABLE Att_Leave_Types;
CREATE TABLE Att_Leave_Types
Leavetype_ID NUMBER
,Leavetype_Desc VARCHAR2(30)
INSERT INTO Att_Leave_Types VALUES(1, 'Annual');
INSERT INTO Att_Leave_Types VALUES(2, 'Sick');
INSERT INTO Att_Leave_Types VALUES(3, 'Casual');
INSERT INTO Att_Leave_Types VALUES(4, 'Long');
INSERT INTO Att_Leave_Types VALUES(5, 'Maternity');
DROP TABLE Att_Emp_Leaves;
CREATE TABLE Att_Emp_Leaves
Emp_ID NUMBER
,leave_date DATE
,leavetype_id NUMBER
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('01-JUL-2006', 'DD-MON-YYYY'), 1);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('10-JUL-2006', 'DD-MON-YYYY'), 1);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('15-JUL-2006', 'DD-MON-YYYY'), 1);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('15-AUG-2006', 'DD-MON-YYYY'), 2);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('25-AUG-2006', 'DD-MON-YYYY'), 3);
INSERT INTO Att_Emp_Leaves VALUES (6902, TO_DATE('15-AUG-2006', 'DD-MON-YYYY'), 2);
INSERT INTO Att_Emp_Leaves VALUES (6902, TO_DATE('25-AUG-2006', 'DD-MON-YYYY'), 3);
SELECT
LP.*
,EL.Leave_date
COLUMN Emp_ID FOR 999999
COLUMN Leave_Month FOR A8
COLUMN Leavetype_ID FOR 999
COLUMN Leavetype_desc FOR A10
COLUMN Leave_Count FOR 999
SELECT
LP.Emp_ID
,TO_CHAR(LP.Leave_Month, 'MON-YYYY') Leave_Month
,LP.Leavetype_ID
,LP.Leavetype_desc
,COUNT(EL.Emp_ID) Leave_Count
FROM
SELECT *
FROM
SELECT
Emp_ID
,ADD_MONTHS(Min_Leave_month, RN - 1) Leave_Month
,Max_Leave_month
FROM
SELECT ROWNUM RN FROM
USER_OBJECTS
WHERE ROWNUM <= 100
SELECT
Emp_ID
,TRUNC(MIN(Leave_date), 'MM') Min_Leave_month
,TRUNC(MAX(Leave_date), 'MM') Max_Leave_month
FROM Att_Emp_Leaves
GROUP BY Emp_ID
WHERE ADD_MONTHS(Min_Leave_month, RN - 1) <= Max_Leave_month
,Att_Leave_Types
-- ORDER BY Emp_ID, Leave_Month, Leavetype_ID
) LP -- Leave periods
,Att_Emp_Leaves EL -- Employee leaves
WHERE EL.Emp_ID(+) = LP.Emp_ID
AND EL.Leavetype_ID(+) = LP.Leavetype_ID
AND EL.Leave_date(+) >= LP.Leave_Month
AND EL.Leave_date(+) < ADD_MONTHS(LP.Leave_Month, 1)
GROUP BY
LP.Emp_ID
,LP.Leave_Month
,LP.Leavetype_ID
,LP.Leavetype_desc
ORDER BY
LP.Emp_ID
,LP.Leave_Month
,LP.Leavetype_ID
EMP_ID LEAVE_MO LEAVETYPE_ID LEAVETYPE_ LEAVE_COUNT
6902 AUG-2006 1 Annual 0
6902 AUG-2006 2 Sick 1
6902 AUG-2006 3 Casual 1
6902 AUG-2006 4 Long 0
6902 AUG-2006 5 Maternity 0
14210 JUL-2006 1 Annual 3
14210 JUL-2006 2 Sick 0
14210 JUL-2006 3 Casual 0
14210 JUL-2006 4 Long 0
14210 JUL-2006 5 Maternity 0
14210 AUG-2006 1 Annual 0
14210 AUG-2006 2 Sick 1
14210 AUG-2006 3 Casual 1
14210 AUG-2006 4 Long 0
14210 AUG-2006 5 Maternity 0
BW -
How to do this template?? Please help me~~
Post Author: maximus85
CA Forum: Crystal Reports
This might sound stupid but i'm a newbie with Crystal Reports.....
I wanna ask how can i do the template where the Rows will look something like first Row blank color then the following Row in Gray Color and so on in repeatitive form.
Thanks alot.............Post Author: pvierheilig
CA Forum: Crystal Reports
Put this in the Color tab formula for the Details section in the Section Editor: If (RecordNumber mod 2) <> 0 Then crSilverelse DefaultAttribute -
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. -
How can we write this in analytical function..
select a.employee_id,a.last_name,b.count from employees a, (select manager_id, count(manager_id) as count from employees group by manager_id) b where a.employee_id=b.manager_id;
As per my requirement I need each manager name and no of employees reporting to him... above query works.. Could anybody help to write the same using analytic function.... Hw this same can be written in effiect way??? (quick performance)
Please also share the link to download some doc to have good understanding of analytical function..
Thanks in advance....are you trying to do a hierarchical type of query?
select ename, count(ename) -1 numr_of_emps_under_this_mgr from emp
connect by empno =prior mgr
group by ename
order by count(ename) desc ;
ENAME NUMR_OF_EMPS_UNDER_THIS_MGR
KING 13
BLAKE 5
JONES 4
CLARK 1
FORD 1
SCOTT 1
ADAMS 0
TURNER 0
MARTIN 0
JAMES 0
SMITH 0
MILLER 0
ALLEN 0
WARD 0Here is the table structure I used (I think you can download it from oracle somewhere)
CREATE TABLE EMP
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10 BYTE),
JOB VARCHAR2(9 BYTE),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
SET DEFINE OFF;
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7369, 'SMITH', 'CLERK', 7902, TO_DATE('12/17/1980 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
800, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7499, 'ALLEN', 'SALESMAN', 7698, TO_DATE('02/20/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1600, 300, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7521, 'WARD', 'SALESMAN', 7698, TO_DATE('02/22/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1250, 500, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7566, 'JONES', 'MANAGER', 7839, TO_DATE('04/02/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
2975, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7654, 'MARTIN', 'SALESMAN', 7698, TO_DATE('09/28/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1250, 1400, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7698, 'BLAKE', 'MANAGER', 7839, TO_DATE('05/01/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
2850, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7782, 'CLARK', 'MANAGER', 7839, TO_DATE('06/09/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
2450, 10);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7788, 'SCOTT', 'ANALYST', 7566, TO_DATE('12/09/1982 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
3000, 20);
Insert into EMP
(EMPNO, ENAME, JOB, HIREDATE, SAL, DEPTNO)
Values
(7839, 'KING', 'PRESIDENT', TO_DATE('11/17/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
5000, 10);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7844, 'TURNER', 'SALESMAN', 7698, TO_DATE('09/08/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1500, 0, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7876, 'ADAMS', 'CLERK', 7788, TO_DATE('01/12/1983 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1100, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7900, 'JAMES', 'CLERK', 7698, TO_DATE('12/03/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
950, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7902, 'FORD', 'ANALYST', 7566, TO_DATE('12/03/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
3000, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7934, 'MILLER', 'CLERK', 7782, TO_DATE('01/23/1982 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1300, 10);
COMMIT; -
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 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 -
Hi out there. To capture a screen shot one uses: Command-Shift-3 or 4. I have done this for a long time. Now suddenly neither screen shot command works anymore. Suggestions how to get this useful function back? Thanks, Georgx
Command-Shift-3 and 4 works just fine on several Macs that I have here.
Try restarting your Mac....or post in the specific support area for your Mac model....for more advice.
https://discussions.apple.com/index.jspa -
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 -
how to ignore nulls in analytic functions ( row_number() and count())
Iam attaching test data can any one help me please
thanks in advanceeeee
CREATE TABLE TEMP_table
ACCTNUM NUMBER,
l_DATE TIMESTAMP(3),
CODE VARCHAR2(35 BYTE),
VENDOR VARCHAR2(35 BYTE)
insert into temp_table values (1,sysdate+1/60,'bso','v1');
insert into temp_table values (1,sysdate+2/60,'bsof','v1');
insert into temp_table values (1,sysdate+3/60,'bsof','v2');
insert into temp_table values (1,sysdate+4/60,'','v1');
ian executing this my ;
SELECT acctnum,l_date,vendor,code_1,
CASE
WHEN code = 'bsof'
AND COUNT (DISTINCT code) OVER (PARTITION BY acctnum, vendor) > 1
AND row_number () OVER (PARTITION BY acctnum, vendor ORDER BY vendor, l_date) != 1
THEN 'yes'
ELSE 'no' END result
FROM (select acctnum,l_date,vendor, code code_1, case when code IN ('bso', 'bsof') then code
else null end code from TEMP_TABLE
ORDER BY acctnum ,l_date);
my result :
1 3/23/2011 5:24:34.000 PM v1 bso no
1 3/23/2011 5:48:36.000 PM v1 bsof yes
1 3/23/2011 6:36:41.000 PM v1 bsof yes
1 3/24/2011 11:55:53.000 AM v1 no
1 3/23/2011 6:12:38.000 PM v2 bsof no
I need to eliminate nulls in top query not in inner query (not using where condition in inner query)
[\code]
Maybe you are looking for
-
New firmware for Nokia E65?
Hi! I've heard many who have updated their Nokia E65 to firmware v3.0633.69.00 but my updater still says v2.0633.65.01 . Where do I get the v3? And my E65 is very very very slow to open menus and messages. Anyone else got this problem? How can I fix
-
Helli Friends I'n installed JDK1.2 on my computer(because of the big size of the newest jdk I can't download the latest version). And my OS is Win XP SP2. Installing will be finished completely and successfully. But the problem is that when I run JAV
-
Possible? access data from another effects plugin
right this sounds complicated so I'm gonna ask if its even possible before i start trying to build this. Picture this scenario. Main comp has layer "A" which is a sub-composition, B. The layer A has my filter on it. In comp B, we have a layer "C" wit
-
Hi all, Is it possible to call a procedure on a package through a process flow module? thkx
-
My Airport Extreme intermittently shuts down completely.
My Airport Extreme (newest model) will shut down completely, all by itself, with the green light completely off. When I unplug and replug the device, it starts again and the green light comes back on after it boots. It's as if a "circuit breaker" c