I need sql query for this plz
9. DATA SET (ALIAS TBL)
SSN Name Background Check Date Review Date
123456789 Bob Smith 4/15/04 5/10/05
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
REQUIREMENTS
Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
EXPECTED RESULTSET
SSN Name Background Check Date Review Date
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
DATA SET (ALIAS TBL)
------------------------------------------------------------------------------------------------------------------|
SSN Name Background Check Date Review Date|
-------------------------------------------------------------------------------------------------------------------|
123456789 Bob Smith 4/15/04 5/10/05
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
REQUIREMENTS
Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
EXPECTED RESULTSET
SSN Name Background CheckDate Review Date
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
Similar Messages
-
I want sql query for this output
hi guys
could u tell how can i write sql query for this out put
i have one table like this
ID ACCOUTID TAX
1 1 A
2 1 B
3 2 C
4 2 D
5 3 E
7 NULL F
8 NULL G
MY OUT PUT MUST BE LIKE THIS
ID AID TAX
2 1 A
4 2 D
7 NULL F
8 NULL G
HERE IN THIS OUTPUT I SHOULD HAVE
MAXIMAM ID VALUE FOR A REPEATED AID VALUES
AND
THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
I KNOW ONE SOLUTION LIKE THIS
SELECT MAX(ID),AID,TAX
FROM TABLE T
GROUP BY AID,TAX
UNION ALL
SELECT ID, AIC,TAX
FROM TABLE T
WHERE AID IS NULL;
BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
COULD U PLZ TELL A SOL.Will this help:
SQL> with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21 and (rn = 1 or ACCOUTID is null)
22 /
ID AID T
2 1 B
4 2 D
8 G
7 F
-- If I leave out the OR condition then you'll get this:
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21* and rn = 1
SQL> /
ID AID T
2 1 B
4 2 D
8 G
--which follows the description you've given, but not the output -
Need sql query for typical scenario
Hello Champs,
I have a scenario where I am suppose to fetch data from a schema which is developed by other team ... (there are no primary keys even)
the table structure is -
Column A Column B Column C Column D
1 h 6 u
1 h 7 u
1 h 8 u
2 g 9 i
2 g 0 i
2 g 7 i
3 t 3 h
3 t 4 h
3 t 5 i
and my output should be exactly like :
1 h 6,7,8 u
2 g 9,0,7 i
3 t 3,4 h
so basically I want comma separated values for column c where remaining column values are same ...
is it possible to achieve this result via SQL?? if not then what is the other solution??
Please help .. I am working in IST and need solution urgently for this .. please help .
TIA,
Regards,
Chintanif you have 11g
WITH t AS (SELECT 1 cola,
'h' colb,
6 colc,
'u' cold
FROM DUAL
UNION
SELECT 1,
'h',
7,
'u'
FROM DUAL
UNION
SELECT 1,
'h',
8,
'u'
FROM DUAL
UNION
SELECT 2,
'g',
9,
'i'
FROM DUAL
UNION
SELECT 2,
'g',
0,
'i'
FROM DUAL
UNION
SELECT 2,
'g',
7,
'i'
FROM DUAL
UNION
SELECT 3,
't',
3,
'h'
FROM DUAL
UNION
SELECT 3,
't',
4,
'h'
FROM DUAL
UNION
SELECT 3,
't',
5,
'i'
FROM DUAL)
SELECT cola, colb, listagg (colc, ',') WITHIN GROUP (ORDER BY colc) colc, cold
FROM t
GROUP BY cola, colb, cold
COLA COLB COLC COLD
1 h 6,7,8 u
2 g 0,7,9 i
3 t 3,4 h
3 t 5 i -
Need SQL code for this logic - - From Serial and To serial no.
In Forms 4.5 Screen I have two text boxes where i will be entering From Serial No
and to serial no.
I want the code which will check whether any number in between these from and to serial exists in a table or not ?
For Example
Select * from t; -- contains
serial number
321-456-789
123-456-654
321-569-986
321-569-987
When I enter from Serial no 321-456-789 and to serial no as 321-456-789.. I should get a message sayinig that 321-456-789 exists.
When I enter from Serial no 321-569-986 and to serial no as 321-569-988.
I should get a message sayinig that 321-456-986 exists.
I should get a message sayinig that 321-456-987 exists.
I should get a message sayinig that 321-456-988 not exists.
is it possible with a SQL query or do we need to go for procedure or temp table ?
If anybody ahving similar code please post it here.
Thanks in Advance
DevenderHi Devender,
Try this :
SQL> select * from t;
SN
321-456-789
123-456-654
321-569-986
321-569-987
SQL> var sn1 varchar2(11)
SQL> exec :sn1 := '321-569-986'
Procédure PL/SQL terminée avec succès.
SQL> var sn2 varchar2(11)
SQL> exec :sn2 := '321-569-988'
Procédure PL/SQL terminée avec succès.
SQL>1 select a.sn, decode(t.sn,null,'does not exists','already exists')
2 from
3 (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
4 ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
5 ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
6 from (select level
7 from dual
8 connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
9 )
10 )a,
11 t
12* where a.sn=t.sn(+)
SQL> /
SN DECODE(T.SN,NUL
321-569-986 already exists
321-569-987 already exists
321-569-988 does not exists
SQL> exec :sn1 := '321-456-789'
Procédure PL/SQL terminée avec succès.
SQL> exec :sn2 := '321-456-789'
Procédure PL/SQL terminée avec succès.
SQL> l
1 select a.sn, decode(t.sn,null,'does not exists','already exists')
2 from
3 (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
4 ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
5 ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
6 from (select level
7 from dual
8 connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
9 )
10 )a,
11 t
12* where a.sn=t.sn(+)
SQL> /
SN DECODE(T.SN,NUL
321-456-789 already exists
SQL> Nicolas. -
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 querry for this logic
Hi,
Edited by: 937506 on Jun 10, 2012 7:35 AM937506 wrote:
Hi,
I have table like this,based on this table data i need one column for example "Value" based on this condition,
KEY A_VAL ETA_VAL RANGE DATE_ID SITE AREA UNIT Monthnumber Year
1111 35 36 50.45 2778 PLANT1 AREA2 CDU-4 8 2011
1111 40 41 50.45 2783 PLANT1 AREA2 CDU-4 8 2011
9010 114 37 50.45 2779 PLANT1 AREA2 CDU-3 8 2011
9010 41 35 50.45 2784 PLANT1 AREA2 CDU-3 8 2011
9011 1500 38 50.45 2789 PLANT2 AREA3 DHT-1 8 2011
9012 43 37 50.45 2774 PLANT1 AREA1 DHT-2 8 2011
9012 38 39 50.45 2781 PLANT1 AREA1 DHT-2 8 2011
9013 39 40 50.45 2782 PLANT1 AREA2 FCC 8 2011How to ask question
SQL and PL/SQL FAQ -
What can be the SQL Query for this requirement ?
Hi,
I have a table with fields like this:
ID DESC PARENT
01 ABC 02
02 ABC1 01
03 ABC2 01
04 ABC4 02
In the above table PARENT column refers to ID column , but actually in SQL query i want to have ID, DESC , and PARENTDESC (i.e., desc value of the corresponding ID)
Actual output that i need is
select ID , DESC , ?? from table where ID=someValue . Now if i provide ID=01 then output should be like this:
ID DESC PARDESC
01 ABC ABC1
Can anyone help what can be the required sql query ?
Edited by: bootstrap on Apr 29, 2011 6:15 AMSELECT T1.ID, T1.DESC, T2.DESC
FROM TABLEA T1, TABLEA T2
WHERE T1.ID='01'
AND T2.ID = T1.PARENT; -
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 -
Need SQL query for PO that do NOT have 3-way match.
The question is -- have any PO"s been generated with other then 3-way match selected - which means they overrode the set-ups in purchasing , to see if there are an PO that do NOT have 3-way match.
Thanks
Mohan.1)Generally when ever we will do Supplier setup we will select in the Receiving tab Match approval level we will select either 3-way ,2-way,4-way or we will keep that as blank.
for that we do not have any direct column in the back end ,so we will use the following conditions.
'2WAY' inspection_required_flag = 'N'
receipt_required_flag = 'N'
'3WAY' inspection_required_flag = 'N'
receipt_required_flag = 'Y'
'4WAY' inspection_required_flag = 'Y'
receipt_required_flag = 'Y'
2)When ever we will create a PO in the shipments level what ever the Match approval level,
we defined in the supplier will automatically reflects in the shipments-More tab.
3)Here i wants to know all the PO's whihc are having Match approval level differences between supplier definiton and PO's match approval level.
(i.e If i will select a supplier for a PO , automatically we will get one Match approvallevel from supplier setup .if i will change that match approval level manually in the PO shipments -More tab i wants to know all that PO by using a SQL query.
4)But for some PO's i am getting receipt_required_flag and inspection_required_flag as null.But in the Supplier setup it may be one of the Matching approval.
Thanks
Mohan. -
Need SQL statement for this logic....
Hi,
I want a SQL statement for updating the following changed last number .
Cuurently its:
SELECT * FROM TEST;
LAST NUMBER CHANGED LAST NUMBER
123518
12355265
123674659
9087648970
After updating with the required SQL statement table should look like
LAST NUMBER CHANGED LAST NUMBER
123518 0000123518
12355265 0012355265
123674659 0123674659
9087648970 9087648970
the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
Appreciate your help.
Thanks in advance
Devenderselect last_number, lpad(to_char(last_number), 10 , '0') FROM test
-
This is my exact requirements
My PNO table formart is
PNO PDate PCount
P001 08/27/05 20
P001 08/29/05 10
P002 08/27/05 20
P003 08/28/05 20
P003 08/28/05 20
I want to display the total (PCount) PNumber for this week.
PNo Sat (27th) Sun(28th) Mon(29th) .........Fri(2/09/2005)
P001 20 0 10 0
P002 20 30 0 0
P003 0 40 0 0
or at least i want to display, i mean if there is no record for P003 on starturday, it will display 0.
PNo Sat (27th)
P001 20
P002 20
P003 0
first iam getting distinct PNo for this week, and check whether these number occurs on saturday if occur then display count otherwise display 0
Millons of thanks in advance...
Message was edited by:
user448874EZECASH@ORCL> select * from pno_table;
PNO PDATE PCOUNT
P001 27-AUG-05 20
P001 29-AUG-05 10
P002 27-AUG-05 20
P003 28-AUG-05 20
P003 28-AUG-05 20
P001 02-SEP-05 10
P001 03-SEP-05 15
P002 03-SEP-05 10
P002 04-SEP-05 10
9 rows selected.
EZECASH@ORCL> select next_day(trunc(sysdate)-7,'sat') d1,next_day(trunc(sysdate)-7,'sat')+1 d2,next_day(trunc(sysdate)-7,'sat')+2 d3,
2 next_day(trunc(sysdate)-7,'sat')+3 d4,next_day(trunc(sysdate)-7,'sat')+4 d5,next_day(trunc(sysdate)-7,'sat')+5 d6,
3 next_day(trunc(sysdate)-7,'sat')+6 d7
4 from dual
5 /
D1 D2 D3 D4 D5 D6 D7
27-AUG-05 28-AUG-05 29-AUG-05 30-AUG-05 31-AUG-05 01-SEP-05 02-SEP-05
EZECASH@ORCL> select pno,sum(decode(trunc(pdate),d1,pcount,0)) day1Sum, sum(decode(trunc(pdate),d2,pcount,0)) day2Sum,
2 sum(decode(trunc(pdate),d3,pcount,0)) day3Sum,sum(decode(trunc(pdate),d4,pcount,0)) day4Sum,
3 sum(decode(trunc(pdate),d5,pcount,0)) day5Sum,sum(decode(trunc(pdate),d6,pcount,0)) day6Sum,
4 sum(decode(trunc(pdate),d7,pcount,0)) day7Sum
5 from pno_table,
6 (select next_day(trunc(sysdate)-7,'sat') d1,next_day(trunc(sysdate)-7,'sat')+1 d2,next_day(trunc(sysdate)-7,'sat')+2 d3,
7 next_day(trunc(sysdate)-7,'sat')+3 d4,next_day(trunc(sysdate)-7,'sat')+4 d5,next_day(trunc(sysdate)-7,'sat')+5 d6,
8 next_day(trunc(sysdate)-7,'sat')+6 d7
9 from dual) w
10 where pdate >= next_day(trunc(sysdate)-7,'sat')
11 group by pno
12 /
PNO DAY1SUM DAY2SUM DAY3SUM DAY4SUM DAY5SUM DAY6SUM DAY7SUM
P001 20 0 10 0 0 0 10
P002 20 0 0 0 0 0 0
P003 0 40 0 0 0 0 0
EZECASH@ORCL> -
How to write a sql query for this condition?
i have one table with columns v_sub,v_visit and v_date and the structure is like this
v_sub v_visit v_date
1 visit-1 01-mar-09
1 visit-2 05-mar-09
1 visit-3 17-mar-09
2 visit-1 04-feb-09
2 visit-2 12-mar-09
2 visit-3 20-mar-09
i want to write a query which check weather it is in chronological order or not.(for v_sub,v_visit and v_date should be in chronological order as above)
and i want to check the condition as below:
v_sub v_visit v_date
1 visit-1 01-mar-09
1 visit-2 05-feb-09
1 visit-3 17-mar-09
2 visit-1 04-feb-09
2 visit-2 12-jan-09
2 visit-3 20-mar-09
Thanks in advanceuse LAG function to get the previous date
SQL> -- sample data
SQL> with t
2 as
3 (
4 select 1 v_sub, 'visit-1' v_visit, to_date('01-mar-09','dd-mon-yy') v_date from dual union all
5 select 1, 'visit-2', to_date('05-mar-09','dd-mon-yy') from dual union all
6 select 1, 'visit-3', to_date('17-mar-09','dd-mon-yy') from dual union all
7 select 2, 'visit-1', to_date('04-feb-09','dd-mon-yy') from dual union all
8 select 2, 'visit-2', to_date('12-mar-09','dd-mon-yy') from dual union all
9 select 2, 'visit-3', to_date('20-mar-09','dd-mon-yy') from dual
10 )
11 -- end of sample data
12 select v_sub, v_visit, v_date, lag(v_date) over(partition by v_sub order by v_visit, v_date) v_previous_date
13 from t
14 /
V_SUB V_VISIT V_DATE V_PREVIOU
1 visit-1 01-MAR-09
1 visit-2 05-MAR-09 01-MAR-09
1 visit-3 17-MAR-09 05-MAR-09
2 visit-1 04-FEB-09
2 visit-2 12-MAR-09 04-FEB-09
2 visit-3 20-MAR-09 12-MAR-09
6 rows selected.Now you can check if the previous_date is less than v_date -
How can i write sql query for this result ?
Hello Dear,
Here is the script first.
CREATE TABLE ACC_TEST(
AD_ID NUMBER,
AD_NAME VARCHAR2(50),
AD_SPM_ID NUMBER);
/data are
Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (136,'Saleh Ahmed',129);
Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (142,'Hamidur Rahman',136);
Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (124,'Jasim Uddin',null);
INSERT INTO ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) VALUES (129,'Sazib',124);I Need The Following Result When I Pass A Value Of Ad_Id. For Example I Pass 142 Then Result Should Be
Select Ad_Id,Ad_Name
From..
where ad_id=142
Ad_Id Ad_Name
136 Saleh Ahmed
129 Sazib
124 Jasim Uddin
If I Pass Ad_Id=136 Then Result Should Be
Ad_Id Ad_Name
129 Sazib
124 Jasim Uddin
If I Pass Ad_Id=129 Then Result Should Be
Ad_Id Ad_Name
124 Jasim Uddin Database 10G XE
Any help will be helpfulHi,
HamidHelal wrote:
WoW ! you acutely got my point. How did you understand that ? lLuck guess. Guessing is usually not the best way to solve problems. It's usually faster and more reliable to say exactly what you want, as well as give an example.
ittle bit more i want to know, if i want to restrict the output not more then 2, what would be sql ?Now you're not even giviing an example!
Maybe you want something like this:
SELECT ad_id
, ad_name
FROM acc_test
WHERE LEVEL BETWEEN 2 AND 3 -- Changed
START WITH ad_id = :target_ad_id
CONNECT BY ad_id = PRIOR ad_spm_id
;which will show jsut the parent and the grandparent of the given row.
I do work with forms developer very much. Sql knowledge is as oracle sql book(cerfitication 9i). But this type of sql isn't available there.
where can i learn this type of sql ? Different sql then ordinary ?Certification is a different topic entirely.
There are books and web sites dealing with more advanced techniques. Sorry, I don't know any well enough to recommend them. Some authors (such as Tom Kyte) are consistently good.
Here are a couple of sites that explain CONNECT BY queries:
http://www.adp-gmbh.ch/ora/sql/connect_by.html
http://www.oradev.com/connect_by.jsp -
What is the sql query for this
table Employee
EmpId
Name
MonthlySalary
DateofJoining
Suggest a sql server query to find out the employee details whose having salary greater than their yers of experiance
nravhadHi ,
As this seems to be a kind of lab exercise question for learning purpose , i am giving you the pseudo code which will help to solve this problem and learn.
select <the requeired columns> from employee table.
where Find the no of years between dateofjoining and current date using DATEDIFF function< monthly salary
if this is not a lab exercise problem for learning purpose , please forgive my ignorance.
Best Regards Sorna
Maybe you are looking for
-
Safari isnt playing youtube videos what do i do?
i do not know why but safari is not playing many youtube videos. how can i fix this problem?
-
Palm Lifedrive wont sync. PC doesn't recognize USB
Hi, I'm having a problem hotsyncing my lifedrive. It's worked fine up until now, but all of a sudden, it won't connect. The PC isn't recognizing that I've plugged the cradle in through my USB ports. I've tried this on 2 computers now and still no luc
-
Cannot Install SAP Crystal Reports 2011 on 64-bit Win 7
I am trying to install the 30-Day Trial of SAP Crystal reports 2011 on a Windows 7 64-bit pc and at the end of the installation, I receive the two errors below. I made sure I clicked 'Ran as Administrator' and under properties under the Compatibility
-
hi, I have a form in document has 2 columns: "yes" and "no". The user of the pdf form clicks yes or no and at the bottom, the form must give the numerical total of yes and no answers. can u pls help me? thanks Ali
-
Hi, Is there a reason why some command doesn't work anymore ? Like : <uitext name="LOGOCLICKURL" value="http://www.mycompanyname.com"/> or <uifont name="FONT_OUTLINE" value="Verdana,11,false,false,true"/> Thanks, Caroline