Need SQL Query ---Urgent
Hi Gurus,
Select * from xxa_test1
invoice_type || LOC_CODE|| seq_no
=========================
DOMESTIC A 1
DOMESTIC B 2
DOMESTIC C 3
Select * from xxa_test2
cust_no || cust_name || loc_code
=======================
1001 Test B
1001 Test C
The Requirement is i want sql query to retrive only one record based on seq no if suppose 2 records retrive in that
B is having seqno 2 and c having seq no 3
that sql query should return only one record which is having min seq no. for example in that B, C only B record should return.
If multiple values returned then the program must check based on the seq no it should take min seq no.
i have written this query
Select *
from xxa_test2 t2
where t2.loc_code in (select t1.loc_code
from xxa_test1 t1
order by Seq_no
where above query is correct or not , i am getting problem with this query.
Please let me know its very urgent
Thanks
Manju
Edited by: venu on Jul 26, 2011 12:50 AM
Something like:
SELECT cust_no, cust_name, loc_code
FROM
(with xxa_test1
as (SELECT 'DOMESTIC' invoice_type, 'A' loc_code, 1 seq_no FROM dual
union all
SELECT 'DOMESTIC', 'B', 2 FROM dual
union all
SELECT 'DOMESTIC', 'C', 3 FROM dual),
xxa_test2
as (SELECT 1001 cust_no, 'Test' cust_name, 'B' loc_code FROM dual
union all
SELECT 1001 , 'Test' , 'C' FROM dual)
SELECT cust_no, cust_name, t2.loc_code, seq_no, min(seq_no) over() min_seq
FROM xxa_test2 t2,xxa_test1 t1
WHERE t2.loc_code = t1.loc_code)
WHERE seq_no = min_seq
SQL> /
CUST_NO CUST L
1001 Test B
Similar Messages
-
Need sql query to import from excel sheet
Hey , i need sql query to import from excel sheet.
i work in a company where i need to daily update the data from excel sheet.
if i get a shortcut method i ill be very thank full to you guys to reduce my work upto 10 %.any query which can inert from excel file?
Sort of. Certainly not anything as simple as what you seem to hope for. Check out this very good PHP class:
PHPExcel - Home -
Need Sql Query that Suppress the repeating rows.
Hi Sir,
I have below data set.
DeptID Sum(SAL) Avg(Sal)
10 1300 1300
10 2450 1300
10 5000 1300
20 800 800
20 1100 800
20 2975 800
20 3000 800
30 800 800
30 1100 800
30 2975 800
40 3000 800
40 4000 900
I Need SQL query that can remove the duplicate or suppress.Just like below data set.
Output:
DeptID Sum(SAL) Avg(Sal)
10 1300 1300
2450 1300
5000 1300
20 800 800
1100 800
2975 800
3000 800
800 800
30 1100 800
2975 800
40 3000 800
4000 900
Could you please help me on this..Your requiremnt is more of a reporting request which should not be handled in SQL. For example in SQL Plus you can use the BREAK command
SQL> break on deptno
SQL> select deptno, ename from emp order by deptno;
DEPTNO ENAME
10 KING
CLARK
20 JONES
SCOTT
SMITH
ADAMS
30 TURNER
MARTIN
WARD
ALLEN
BLAKE
11 rows selected.
SQL>
But if you still wish to do it in SQL you can use ROW_NUMBER analytic function and achieve it like this
select decode(rno, 1, deptno) deptno
, ename
from (
select row_number() over(partition by deptno order by ename) rno
, deptno
, ename
from emp -
Need sql query or pl/sql query urgent
Hi Experts,
The requirement is that
SELECT 'N' flag, sysdate init_date,
'' vendor_name,
DECODE (pa.address_type,
'P', 'Present Address',
'R', 'Permanent Address',
pa.address_type
) address_type,
pa.address_line1
|| ','
|| pa.address_line2
|| ','
|| pa.town_or_city
|| ','
|| meaning
|| ','
|| pa.POSTAL_CODE "Address",
TRUNC (TO_CHAR (pa.date_from, 'YYYY')) YEAR,
TO_CHAR (pa.date_from, 'MON') MONTH,''station
FROM per_addresses pa, fnd_lookup_values, per_all_people_f pf
WHERE (pf.employee_number = :1 or pf.APPLICANT_NUMBER = :2)
and pf.EFFECTIVE_END_DATE='31-DEC-4712'
AND pa.person_id = pf.person_id
AND pa.business_group_id = 42
--AND pa.date_to IS NULL
AND lookup_type = 'PER_US_COUNTRY_CODE'
AND lookup_code = pa.country
AND enabled_flag = 'Y'
AND (end_date_active IS NULL OR end_date_active > SYSDATE)
if i run the above query the output is coming like that
Present Address | Flat No. 1201, OC - 15, Orange County, Plot No. GH - 4,Ahinsa Khand 1st, Indrapuram,Ghaziabad,India,201010| 2,010| JUL
Permanent Address | Q.No. 354, Sector - 3 / B,,Bokaro Steel City,India,827003 |2,010 |JUL
Present Address | 4, Sitara,Chandra Reddy layout, S.T. Bed,Bangalore,India,0| 2,006| JAN
Present Address | 101,,Ushma Urja Apartments,Noida,India,201301 | 2,006 | JUL
Permanent Address | F-19, Maccon Colony, Opp. DAV Shyamali School,,Ranchi,India,834002 | 2,009 | FEB
Present Address | Flat no. 604, B - 1, Krishna Apra Gardens,Vaibhav Khand, Plot - 7,Ghaziabad,India,201010 | 2,009 FEB
But the requirement is the output should come like that
Permanent Address |Q.No. 354, Sector - 3 / B,,Bokaro Steel City,India,827003| 2,010 |JUL
Permanent Address 1| F-19, Maccon Colony, Opp. DAV Shyamali School,,Ranchi,India,834002| 2,009 | FEB
Present Address | Flat No. 1201, OC - 15, Orange County, Plot No. GH - 4,Ahinsa Khand 1st, Indrapuram,Ghaziabad,India,201010| 2,010 | JUL
Present Address 1 | Flat no. 604, B - 1, Krishna Apra Gardens,Vaibhav Khand, Plot - 7,Ghaziabad,India,201010| 2,009 | FEB
Present Address 2 | 101,,Ushma Urja Apartments,Noida,India,201301| 2,006| JUL
Present Address 3 | 4, Sitara,Chandra Reddy layout, S.T. Bed,Bangalore,India,0 | 2,006| JAN
Please provide logice how i need to write a sql query or procedure or function or package
Thanks & Regards
VenuYou can use analytics here :
SELECT
flag,
init_date,
vendor_name,
address_type ||' ' ||rn AS address_type,
Address,
YEAR,
MONTH,
station
FROM
SELECT
'N' flag,
sysdate init_date,
'' vendor_name,
DECODE (pa.address_type, 'P', 'Present Address', 'R','Permanent Address', pa.address_type ) address_type,
row_number() over(partition BY pa.address_type order by 1) AS rn,
pa.address_line1
|| ','
|| pa.address_line2
|| ','
|| pa.town_or_city
|| ','
|| meaning
|| ','
|| pa.POSTAL_CODE "Address",
TRUNC (TO_CHAR (pa.date_from, 'YYYY')) YEAR,
TO_CHAR (pa.date_from, 'MON') MONTH,
'' station
FROM
per_addresses pa,
fnd_lookup_values,
per_all_people_f pf
WHERE
pf.employee_number = :1
OR pf.APPLICANT_NUMBER = :2
AND pf.EFFECTIVE_END_DATE='31-DEC-4712'
AND pa.person_id = pf.person_id
AND pa.business_group_id = 42
--AND pa.date_to IS NULL
AND lookup_type = 'PER_US_COUNTRY_CODE'
AND lookup_code = pa.country
AND enabled_flag = 'Y'
AND
end_date_active IS NULL
OR end_date_active > SYSDATE
); -
HI
I want a sql query i.e., all employees list which are having lessthan maximum salary of manager in same departmnet;
my table is like this
employees
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
if need the department table
departments:
DEPARTMENT_ID
NOT NULL NUMBER(4)
DEPARTMENT_NAME
NOT NULL VARCHAR2(30)
MANAGER_ID
NUMBER(6)
LOCATION_ID
NUMBER(4)Try this:
select
employees.last_name || ', ' || employees.first_name “Employee”,
employees.salary “Emp Salary”,
sub.salary “Mgr Salary”,
employees.department_id “Department”
from
employees,
( select
mgr.department_id dept,
max(mgr.salary) salary
from
employees,
employees mgr
where
employees.mgr = mgr.employee_id
group by
mgr.department_id) sub
where
employees.department_id = sub.dept
and employees.salary < sub.salary
Jeff -
Need sql query to remove duplicates using UNION ALL clause
Hi,
I have a sql query which has UNION clause.But the UNION clause is causing some performance issues.
To overcome that I have used UNION ALL to improve performance but its returning duplicates.
Kindly anyone send a sample SQL query where my primary objective is used to use UNION ALL clause and to consider unique rows (elimating duplicate
ones)
Any help will be needful for me
Thanks and Regardswhy not UNION? :(
another way also use MINUS
SQL>
SQL> with t as
2 (
3 select 1 if from dual union all
4 select 2 if from dual union all
5 select 1 if from dual union all
6 select 3 if from dual union all
7 select 3 if from dual
8 )
9 ,t2 as
10 (
11 select 1 if from dual union all
12 select 2 if from dual union all
13 select 3 if from dual union all
14 select 4 if from dual union all
15 select 5 if from dual
16 )
17 (select if from t
18 union all
19 select if from t2)
20 /
IF
1
2
1
3
3
1
2
3
4
5
10 rows selected
SQL> so
SQL>
SQL> with t as
2 (
3 select 1 if from dual union all
4 select 2 if from dual union all
5 select 1 if from dual union all
6 select 3 if from dual union all
7 select 3 if from dual
8 )
9 ,t2 as
10 (
11 select 1 if from dual union all
12 select 2 if from dual union all
13 select 3 if from dual union all
14 select 4 if from dual union all
15 select 5 if from dual
16 )
17 (select if from t
18 union all
19 select if from t2)
20 minus
21 select -99 from dual
22 /
IF
1
2
3
4
5
SQL> -
Need sql query to find out Joins attached with folders in Discoverer
Hi,
Can anyone let me know the sql query which can be used to identify the joins which are attached to the folders.
Actually we have to identify all the joins conditions from folders those are migrated from one instance to others.
Thanks
abhishekI recommend that you implement the admin EUL supplied by oracle, you can get there a lot of repository information (metalink note: 556932.1).
Try to use this (maybe you will need some pkg's):
SELECT
DECODE(KEYS.FK_MANDATORY,
1,
'Always exist in master folder',
'Might not exist in master folder') "Detail Item values",
EUL10G_US.EUL5_GET_JOIN(EXP.EXP_ID, 'N') "Join Master --> Detail",
KEYS.KEY_DESCRIPTION JOIN_DESCRIPTION,
KEYS.KEY_DEVELOPER_KEY JOIN_IDENTIFIER,
KEYS.KEY_NAME JOIN_NAME,
DECODE(SUBSTR(KEYS.KEY_NAME, 1, 19),
'AUTO_GENERATED_NAME',
'Yes',
'No') "AutoGen",
DECODE(DECODE(SUBSTR(KEYS.KEY_NAME, 1, 19),
'AUTO_GENERATED_NAME',
'Yes',
'No') ,
'Yes',
EUL10G_US.EUL5_GET_JOIN(EXP.EXP_ID),
KEYS.KEY_NAME) "Actual Join Name",
KEYS.KEY_UPDATED_DATE JOIN_LAST_UPDATE,
DECODE(KEYS.FK_ONE_TO_ONE, 1, 'One to one join', NULL) "One to One join",
DECODE(KEYS.FK_MSTR_NO_DETAIL,
1,
'Outer join on detail' || CHR(10),
NULL) "Outer Join on Detail",
DECODE(KEYS.FK_DTL_NO_MASTER,
1,
'Outer join on master' || CHR(10),
NULL) "Outer Join on Master",
DECODE(KEYS.FK_MSTR_NO_DETAIL,
1,
'Outer join on detail' || CHR(10),
NULL) || DECODE(KEYS.FK_DTL_NO_MASTER,
1,
'Outer join on master' || CHR(10),
NULL) ||
DECODE(KEYS.FK_ONE_TO_ONE, 1, 'One to one join', NULL) "Optional Join Configurations",
OBJ.OBJ_NAME "MASTER_FOLDER",
OBJ_DETAIL.OBJ_NAME "DETAIL_FOLDER"
FROM EUL10G_US.EUL5_OBJS OBJ,
EUL10G_US.EUL5_EXPRESSIONS EXP,
EUL10G_US.EUL5_KEY_CONS KEYS,
EUL10G_US.EUL5_OBJS OBJ_DETAIL
WHERE ((KEYS.KEY_ID = EXP.JP_KEY_ID) AND
(OBJ.OBJ_ID = KEYS.FK_OBJ_ID_REMOTE) AND
(OBJ_DETAIL.OBJ_ID = keys.KEY_OBJ_ID)); -
Need sql query to find out Joins attached with folders
Hi,
Can anyone let me know the sql query which can be used to identify the joins which are attached to the folders.
We dont want to see those from front end(disc admin).
Thanks
abhishekabhishek - This is the Application Express forum. I have no idea what you are asking but it may need to be directed to a different forum.
Scott -
Need sql query to find ten records in sequential manner
Plz help me
I need to have ten records on my page. at the bottom of the page, i want to dispaly the number of pages that have records , just as a google page shows at the bottom. if the moves user moves to the next page , the next ten records must be displayed. suppose the user selects and clicks 5th page then the records on that page are displayed.How can i write the sql query corresponding to this specificationi don't want all records to be fetched at the same time and put on the server, rather whenever the page is opened , the corresponding records are fetched and displayedHi
Maybe you should use a CachedRowSet.
Look this:
http://developer.java.sun.com/developer/technicalArticles/javaserverpages/cachedrowset/
This page has a example that will help you. -
Hi All,
i have input like
'JEFFRJON-Sales Manager-JEFFRJON'
'TBH01-JEFFRJON-Apps Agile Rep-JEFFRJON'
Need output only
Sales Manager
Apps Agile Rep
Please give me the sql query for this....anbarasan wrote:
Hi All,
i have input like
'JEFFRJON-Sales Manager-JEFFRJON'
'TBH01-JEFFRJON-Apps Agile Rep-JEFFRJON'
Need output only
Sales Manager
Apps Agile Rep
Please give me the sql query for this....You should really provide more info - like database version - so that people don't have to make assumptions when they try to help you. Based on limited requirements;
with t as (
select 'JEFFRJON-Sales Manager-JEFFRJON' str from dual union all
select 'TBH01-JEFFRJON-Apps Agile Rep-JEFFRJON' from dual)
select regexp_replace(str, '(.*JEFFRJON-)(.*)(-JEFFRJON.*)','\2') c
from t;
C
Sales Manager
Apps Agile Rep -
I would be thankful if anyone could please advise on the sql question as follows:
id1,dept1,JOHN,12-12-1991
id2,dept1,JOHN,12-12-1992
id3,dept1,JOHN,12-12-1993
id4,dept1,SMITH,11-10-1994
id5,dept1,SMITH,12-12-1995
id6,dept1,SMITH,12-12-1996
id7,dept1,CHRIS,07-07-1997
id8,dept1,CHRIS,12-12-1998
I need a query to get the the data when a particular employee was replaced
as follows:
name,date_replaced
JOHN,11-10-1993
SMITH,07-07-1997
CHRIS,null
Any suggestions are most welcome.1 select distinct name, last_value(NextHired) over (ORDER BY dept,name)
2 from
3 (with emp as
4 (select 'id1' id,
5 'dept1' dept,
6 'JOHN' name,
7 to_date('12-12-1991' ,'DD-MM-YYYY') hiredate from dual
8 union
9 select 'id2','dept1','JOHN',to_date('12-12-1992' ,'DD-MM-YYYY') from dual
10 union
11 select 'id3','dept1','JOHN',to_date('12-12-1993' ,'DD-MM-YYYY') from dual
12 union
13 select 'id4','dept1','SMITH',to_date('11-10-1994','DD-MM-YYYY') from dual
14 union
15 select 'id5','dept1','SMITH',to_date('12-12-1995','DD-MM-YYYY') from dual
16 union
17 select 'id6','dept1','SMITH',to_date('12-12-1996','DD-MM-YYYY') from dual
18 union
19 select 'id7','dept1','CHRIS',to_date('07-07-1997','DD-MM-YYYY') from dual
20 union
21 select 'id8','dept1','CHRIS',to_date('12-12-1998','DD-MM-YYYY') from dual)
22 select id,name, dept,lead (hiredate,1) OVER (ORDER BY hiredate) AS NextHired
23 from emp
24 order by id, dept)
25* order by last_value(NextHired) over (ORDER BY dept,name)
SQL> /
JOHN 11/10/94
SMITH 07/07/97
CHRIS
SQL> Nicolas.
Message was edited by:
N. Gasparotto
Hmm, rajeevm, you wrote JOHN,11-10-1993, but it seems it's a mistake... isn't it ? -
Help me write a SQL query; urgent
Hi, can somebody please help me write a SQL query.
I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
Does anybody help me please ?
thanks alot.Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
I'm not sure exactly what you want.
Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
If so, it would be like this, I think: insert into t4
select t1.c1
, t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
from t1, t2, t3
where t2.c1 = t1.c1
and t3.c1 = t1.c1If that's not what you want, please clarify.
And next time maybe you should post your SQL question in a SQL forum. -
I Have some 3 tables for example as below
Order Table :_
Order_ID Order Name
1 Order1
2 Order2
3 Order3
Item Table:_
Item_id Item_name Order_id
100 item1 1
101 item2 1
102 item3 2
201 item4 2
202 item1 3
203 item2 3
Customer table:_
Customer_id Cust_Name Order_id
500 a1 1
501 a2 1
502 a3 2
503 a4 2
504 a5 3
505 a6 3
I need a query to fetch the Order name from the Order tables by giving input as Items and Customer details.
Example: Input as
Case 1:
Items: Item1, Item2
Customers: a1,a2
Result should be Order1
Case 2:
Items : Item1,Item2
Customers: a1,a2,a5,a6
Result should be order1,order3
Use Case:
When both my Items as well as customer are satisfied for a single order , then only those order details has to be displayed else null.983832 wrote:
Sorry I am new to this forumThen I suggest you to start reading: SQL and PL/SQL FAQ
Particularly post CREATE TABLE and INSERT statements, explain the logic and post your expected output.
When you put some code or output please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
It's also considered a good practice to mark questions as answered when the answers are satisfying your question or provide additional details.
Regards.
Al -
Need sql query for like operation.
Hi All,
i have table like name column and contain the data like
ibm 100
ibm 200
ibm 300
a2b
a
b
c
like this ....
but sql query need search using like or any regular expression---
select * from table where name like (ibm 200 and ibm 300).
and i don't want use like this select * from table where name like' ibm 200' or name like 'ibm 300').
can you please any body help to correct the above query...
Edited by: anbarasan on Oct 16, 2011 10:02 PMWITH t AS
(SELECT 'ibm 100' NAME
FROM DUAL
UNION ALL
SELECT 'ibm 200' NAME
FROM DUAL
UNION ALL
SELECT 'ibm 300' NAME
FROM DUAL
UNION ALL
SELECT 'a2b' NAME
FROM DUAL)
SELECT *from t where REGEXP_LIKE (name, 'ibm')
and REGEXP_LIKE (name, '100|200') -
Need SQl Query for Revenue Code and Revenue Amount in Receivables
Hi,
I need a SQL Query to develop data set for the following columns:
Revenue Code,Revenue Code Description,Invoice Amount,Revenue Amount,Original Invoice Number,Original Invoice Date.
Can i get from ra_cust_trx_line_gl_dist_all and ra_customer_trx_all and ra_customer_trx_lines_all by joining them.But for the columns whcih to take
i am in dilemma.
Kindly any help will be needful for meHi,
I need a SQL Query to develop data set for the following columns:
Revenue Code,Revenue Code Description,Invoice Amount,Revenue Amount,Original Invoice Number,Original Invoice Date.
Can i get from ra_cust_trx_line_gl_dist_all and ra_customer_trx_all and ra_customer_trx_lines_all by joining them.But for the columns whcih to take
i am in dilemma.
Kindly any help will be needful for me
Maybe you are looking for
-
K9N4 SLI - Lack of 125W CPU Support
Hello, Just wondering why does this board not support any 125W CPU's? I was looking at getting one of these boards to throw in a 6000 X2 but according to the website, this board only supports the 89W version, which is unavailable where I am. I've see
-
Default Cost element pick up despite there is no setting in config.defined
Hi, During external services(control key PM03), system picks up default cost element in maintenance order. Irony is that I have set no default cost element in "External procurement service in Config". I have also checked there is no default user data
-
How do I paste the file I converted to my word document?
How do I paste the converted file to my document
-
WebVPN using External Authentication
I have a VPN concentrator 3005 that is configured for WebVPN which works great if I login with a local user. I would like to authenticate my users through our LDAP. I created a SSLusers group that is setup for external authentication. The SSLusers gr
-
Batch import of photo information
Is there any way to import information about a batch of photos from (say) an Excel file? I am thinking about Title, Date, and Description in particular. This is what I want to do. I am about to scan my 2000+ slide photos into iPhoto using a simple