SQL & PL/SQL :: Employees Joined In Each Month
Jan 28, 2011
getting the following kind of output.
I would like to get Each year and the number of employees joined in the corresponding month for jan, feb, mar and april from emp table.
A sample output looks like below.
YEAR JAN FEB MAR APRIL
2000 4 2 1 2
2001 2 1 1 5
2002 2 4 2 6
2004 2 4 1 4
View 7 Replies
ADVERTISEMENT
Jun 27, 2011
Query to find out employees who are all joined before Manager.
For Example the Table may look like.
EMPIDDesignationDateJoined
E101Programmer10-Jan-04
E102Programmer22-Mar-04
E103Analyst 14-Jan-05
E104Designer20-Dec-06
E105Tester 20-Nov-07
E106Manager 11-Oct-08
E107Programmer20-Nov-09
E108Coordinator12-Dec-10
E109DB Admin10-Feb-07
E110DB Analyst10-Aug-05
The out put must be..
EMPIDDesignationDateJoined
E101Programmer10-Jan-04
E102Programmer22-Mar-04
E103Analyst 14-Jan-05
E104Designer20-Dec-06
E105Tester 20-Nov-07
E109DB Admin10-Feb-07
View 4 Replies
View Related
Aug 21, 2013
I am having a table employees with columns
1.employee_id
2.department_id
3.hire_date
Display department ID, year, and Number of employees joined?
View 10 Replies
View Related
Jun 4, 2013
I have a requirement to list the data month wise dynamically where month data is also in the same table, hopefully the below posts should bring more clarity to my requirements.
1. Table creation:
Create table T1 (account_no varchar2(15), area_code varchar2(2), bill_month date, consumption number);
2. List table content:
select * from T1;
account_no area_code bill_month consumption
Q00001Q31-Jan-12125
Q00002Q31-Jan-1265
Q00003Q28-Feb-12219
Q00004Q28-Feb-12805
Q00005Q28-Feb-1254
Q00001Q31-Mar-12234
Q00002Q31-Mar-12454
Q00003Q31-Mar-12232
Q00004Q30-Apr-1221
Q00005Q30-Apr-12218
Q00001Q30-Apr-1254
Q00002Q31-May-1219
Q00003Q31-May-1287
Q00004Q30-Jun-12187
Q00005Q30-Jun-1278
so on......so on......so on......so on......
3. Expected output:
account_no area_code Jan-12 Feb-12 Mar-12 Apr-12 May-12Jun-12Jul-12Aug-12Sep-12Oct-12Nov-12Dec-12
Q00001 Q 125 548 2345487423154821518738721512
Q00002 Q 65 127 45487819357831585683152878
Q00003 Q 545 219 2328738735188745897313
Q00004 Q 78 805 1221218187885718387389787138
Q00005 Q 541 54 2621878778386538698182
With the conventional query I hope this is impossible,
View 2 Replies
View Related
Jun 17, 2008
I have a schema whereby a table is not joined with other tables.
the info on that table can be gotten manually (by doing a query) and then using that info in another query. so is there a way of getting info from that table?
View 8 Replies
View Related
Jul 22, 2010
I have the following, simplified, query involving 3 tables:
Table 1
ID---Student
1----Terry
2----Gilbert
3 ---Egbert
4 ---Norris
Table 2
ID--Base_ID--Base_Name
1 --F100 ------St. Vincents
3 --F102 ------AB Junior High
4 --F103 ------CD Middle School
Table 3
ID--Choice_order_ID--Secondary_Base_Choice
1---Co1-------------School A
1---Co2-------------School B
1---Co3-------------School C
2---Co1-------------School B
2---Co2-------------School A
2---Co3-------------(null)
3---Co1-------------School C
3---Co2-------------School A
3---Co3-------------School B
I use the following query:
select table1.student, table2.base_name
from table 1, table2,
where table1.id = table2.id (+)
which returns the student and the base name they attend, i.e.
Student---Base_Name
Terry-----St. Vincents
Gilbert----(null)
However, I need to also list their school Secondary_Base_Choices horizontally, in the following format,
I.e.
Student---Base_Name----Base_Choice_1---Base_Choice_2---Base_Choice_3
Terry-----St. Vincents----School A----------School B-----------School C
Gilbert----(NULL)---------'NO DATA'--------'NO DATA'----------'NO DATA'
Egbert----AB Junior H----School B----------School A-----------'NO DATA'
View 3 Replies
View Related
May 16, 2013
Using 11gR2, windows 7 client machine. I need to update the table missing_volume (below), where I need to calculate the estimated_missing column. The calculation of estimated_missing column for current month needs previous month numbers (as commented inside the code below). I want the output like the first table. Notice the records start from January, hence estimated_missing for January can't be calculated, but for the the rest of the months it can be done by simply changing 'yr' and 'mnth' (commented inside the code towards the end).
yr mnth location volume actual_missing expected_missing estimated_missing
---------------------------------------------------------------------------------------------------------------------------------
2013 January loc1 48037 24 57
2013 February loc1 47960 3660 53 24
2013 March loc1 55007 78 57 28
2013 April loc1 54345 72 58 77The code:
UPDATE missing_volume g
[Code]....
The code does calculate correct number for 'estimated_missing' as I run the code for each month, but the problem is while updating the current month it also erases the record for previous month. E.g. as can be seen below, after I updated April the column only has the record for April, previous month record is gone, similarly updating March removed February, etc. I can't understand why it's happening!! Here is the output I get:
yr mnth location volume actual_missing expected_missing estimated_missing
---------------------------------------------------------------------------------------------------------------------------------
2013 January loc1 48037 24 57
2013 February loc1 47960 3660 53
2013 March loc1 55007 78 57
2013 April loc1 54345 72 58 77
why it's happening (I mean where is the flaw in the code) and how to get the desired output (first table).
View 5 Replies
View Related
Nov 25, 2010
I need for each date sum the values from the begin of the year to present date. In January I will have the value of this month, on February I must sum the value of this month and the value of the month before, and so on, at the end of the year.
Date input
SELECT ID_CLIENT, DT_REG, VAL
FROM (
SELECT 1 as ID_CLIENT, TO_DATE('20100101', 'YYYYMMDD') as DT_REG, 200 as VAL FROM DUAL UNION
SELECT 1 as ID_CLIENT, TO_DATE('20100201', 'YYYYMMDD') as DT_REG, 100 as VAL FROM DUAL UNION
SELECT 1 as ID_CLIENT, TO_DATE('20100301', 'YYYYMMDD') as DT_REG, 200 as VAL FROM DUAL UNION
SELECT 1 as ID_CLIENT, TO_DATE('20100401', 'YYYYMMDD') as DT_REG, 150 as VAL FROM DUAL UNION
SELECT 1 as ID_CLIENT, TO_DATE('20100501', 'YYYYMMDD') as DT_REG, 100 as VAL FROM DUAL UNION
SELECT 2 as ID_CLIENT, TO_DATE('20100101', 'YYYYMMDD') as DT_REG, 100 as VAL FROM DUAL UNION
SELECT 2 as ID_CLIENT, TO_DATE('20100301', 'YYYYMMDD') as DT_REG, 220 as VAL FROM DUAL UNION
SELECT 2 as ID_CLIENT, TO_DATE('20100501', 'YYYYMMDD') as DT_REG, 500 as VAL FROM DUAL UNION
SELECT 3 as ID_CLIENT, TO_DATE('20100201', 'YYYYMMDD') as DT_REG, 150 as VAL FROM DUAL UNION
SELECT 3 as ID_CLIENT, TO_DATE('20100501', 'YYYYMMDD') as DT_REG, 100 as VAL FROM DUAL);
Result
ID_CLIENTDT_REGVAL
101/01/2010200
101/02/2010300
101/03/2010500
101/04/2010650
101/05/2010750
201/01/2010100
201/03/2010320
201/05/2010820
301/02/2010150
301/05/2010250
View 17 Replies
View Related
Jun 17, 2011
I have Employees and Salary columns in emp table. So i have nearly 200 employees.
I need to show top 10 employees who has maximum salary.
View 4 Replies
View Related
Sep 27, 2010
For table employees with
EMPLOYEES
__________________________________________
EMPID NAME MANAGERID
------------------------------------------
34 Amy
17 Ben 34
5 Chris 34
10 Don 5
...
How can we use SQL to get all employees under one manager , either direct or indirect
I only can think the following SQL to get the first direct employee.
select e1.empid
from employees e1, employees e2
where e1.managerid = e2.empid
and e2.empid = '34';
Perhaps we could put it in PL/SQL procedure to do recursive call?
View 1 Replies
View Related
Feb 24, 2013
I have a table:
create table employee_function
(
id_emloyee number,
id_function number
);
with clients and their functions.
I want to extract all employes who has 2 functions (ex:id_function = 1 and id_function=2)
View 3 Replies
View Related
Apr 28, 2010
Select top 2 * from employees;
TOP command or function is suitable for oracle 10g SQL
if not then for top analysis what should need to use..is this query work in Oracle SQL 10g?
View 4 Replies
View Related
Sep 11, 2012
I borrowed some code fragments from other posts and put together a sql query. I think there is a better method in other posts but I couldn't get them working.
I'm trying to get the count of hired employee(s) using the EMP table. I want from the first hire to the last and ALL in between. If there were no hires in that window, I want 0.
WITH minmax AS
(SELECT MIN(last_day(hiredate)) fmonth, MAX(last_day(hiredate)) lmonth
FROM emp),
cal AS
(SELECT add_months(fmonth, LEVEL - 1) mnth
FROM minmax
CONNECT BY LEVEL <= months_between(lmonth, fmonth) + 1),
vals AS
(SELECT extract(YEAR FROM mnth) YEAR, extract(MONTH FROM mnth) MONTH
FROM cal),
data AS
(SELECT extract(YEAR FROM hiredate) YEAR,
extract(MONTH FROM hiredate) MONTH,
COUNT(*) hired_cnt
[code]...
View 2 Replies
View Related
Aug 16, 2012
I use a table taht i call C where the value of a field ("Type") is always a concat of values coming from more than 2 tables (A et C)
select A.Numero, B.date, B.commentaire,C.Libelle
from A, B, C
where A.codeLibelle = C.codeLibelle
and CONCAT(A.Numero, CONCAT(A.DemNumero, C.Libelle)) = B.Type (+)
when i execute this statement, i obtain
ORA-01417: a table may be outer joined to at most one other table
I have another request where it works fine and where i have concat of fields from only a single table:
select A.Numero, B.date, B.commentaire,C.Libelle
from A, B
where CONCAT(A.Numero, A.DemNumero) = B.Type (+)
In the first request Oracle seems to not accept a join with more than 2 tables
View 7 Replies
View Related
Aug 19, 2010
SELECT *
FROM EMP E,DEPT D
WHERE D.DEPTNO = CASE WHEN COMM IS NULL THEN E.DEPTNO ELSE E.DEPTNO(+) END;
It is giving error on executing saying
ORA-01417 - a table may be outer joined to at most one other table.
Why it is giving this error,
How can i write such a query, since it my requirement
View 8 Replies
View Related
Jan 8, 2012
I am trying to update of job_id column of employees table for employee number 205 two times one after another. First time job_id column of employees table for employee number 205 is updated with new job_id. But second time job_id column of employees for employee number 205 table can not be updated. Oracle returns the following errors
HR:orcl > update employees set JOB_ID='AC_MGR' where employee_id=205;
update employees set JOB_ID='AC_MGR' where employee_id=205
*
ERROR at line 1:
ORA-00001: unique constraint (HR.JHIST_EMP_ID_ST_DATE_PK) violated
ORA-06512: at "HR.ADD_JOB_HISTORY", line 10
ORA-06512: at "HR.UPDATE_JOB_HISTORY", line 2
ORA-04088: error during execution of trigger 'HR.UPDATE_JOB_HISTORY'
As there is composite primary key using employee_id and start_date column.how to update same employee job_id twice.AS we can see from job_history table, the record for employee 200 is as follow
EMPLOYEE_ID START_DATE END_DATE JOB_ID DEPARTMENT_ID
----------- ----------- ---------- ---------- -------------
200 17-SEP-1987 17-JUN-1993 AD_ASST 90
200 01-JUL-1994 31-DEC-1998 AC_ACCOUNT 90
So how can i do the same for employee 205 without changing hire_date after first job_id update. Since for every update of job_id fires trigger. To insert row in job_history table employee id and start_date must be unique each time. HERE hire_date of employees table is used as start_date of job_id table. how it was possible for employee id 200 to change job_id twice?
View 4 Replies
View Related
Oct 12, 2011
Assign employees to their jobs in consideration the maximum number of employees to each jobs is 5 employee plus each job has own the maximum number of employees
we need the maximum number of employees for each job 5 to be variable when need to change this maximum for certain job , change this number from database (form the from of job ) not form code )
tables
emp
emp_no
name
manager
hiredate
salary
job
job_no
job
you can add tables or attributes to tables to complete you business.
View 10 Replies
View Related
Jul 24, 2013
I want TO find out FIRST two employee joined IN A particular department WITH department information.THE relation IS basically FROM THE scott SCHEMA.I tried LIKE AS follows. IS there ANY other way FOR best PERFORMANCE.
SELECT deptno,dname,loc,
Max(Decode(rn, 1, hiredate))hiredate1,
Max(Decode(rn, 1, ename)) employee1,
Max(Decode(rn, 2, hiredate))hiredate2,
Max(Decode(rn, 2, ename)) employee2
FROM (SELECT d.deptno,dname,loc,hiredate,ename,Row_number() over(PARTITION BY e.deptno ORDER BY hiredate) rn
FROM dept d, emp e
WHERE d.deptno = e.deptno(+))
GROUP BY deptno,dname,loc;
View 15 Replies
View Related
Dec 21, 2010
write a query to see how many(no) employees getting salary 3000 & what are their names respectively.
View 2 Replies
View Related
Sep 21, 2010
I have to display count of employees that belongs to different categories.
is the situatio There is a category table CATEGORY with three columns (PK,NAME,TREEPOSITION) and we have categories A, B, C these three categories can further have sub-categories so the treeposition for the sub categories will be followed by their root category with _ 'symbol'
Now I have table for the employees with 3 columns (pk,name,category_id), where employees.category_id=category.pk So I want to calculate the number of employees in each category or sub-category.
since the number of categories will be large and each will be having different names so going through names will be bad option left is grouping through the treepostion
the problem is I cant use like using IN for the TREEPOSITION. .
TABLE EMPLOYEES ( PK,NAME,CATEGORY_ID)
TBALE CATEGORIES (PK,NAME,TREEPOSITION)
View 2 Replies
View Related
Mar 4, 2013
Get the highly paid two employees from each department with all details?
View 3 Replies
View Related
Aug 21, 2012
I want to update the names of employees by concatenating with A for DEPT 20. For that I have written the following PL/SQL block. But instead of one A the ename are concatenating with five AAAAA s.
DECLARE
TYPE lt_emp_arr IS TABLE OF t_emp.deptno%TYPE;
l_emp_arr lt_emp_arr;
BEGIN
SELECT deptno
BULK COLLECT INTO l_emp_arr
[code].......
I got the following out put.
EMPNOENAME SAL DEPTNO
7566JONESAAAAA200020
7788SCOTTAAAAA300020
7902FORDAAAAA300020
7369SMITHAAAAA800020
7876ADAMSAAAAA 130020
But I want the output like this
EMPNOENAMESAL DEPTNO
7566JONESA200020
7788SCOTTA300020
7902FORDA300020
7369SMITHA800020
7876ADAMSA 130020
View 1 Replies
View Related
Aug 17, 2010
Need pl/sql block to fetch all the emails of all the employees from the database and separate them by semicolon....
View 4 Replies
View Related
Aug 22, 2012
How can I create a query to display the total no of employees and, of that total, the number of employees hired in 1995,1996,1997,1998.
I am using Oracle® Database Express Edition 10g Release 2 (10.2)
View 3 Replies
View Related
Aug 21, 2012
I want to update the names of employees by concatnating with A for DEPT 20. For that I have writteh the following PL/SQL block. But instead of one A the ename are concatinating with five AAAAA s.
DECLARE
TYPE lt_emp_arr IS TABLE OF t_emp.deptno%TYPE;
l_emp_arr lt_emp_arr;
BEGIN
SELECT deptno
[Code]...
/I got the following out put.
EMPNO ENAME SAL DEPTNO
7566 JONESAAAAA 2000 20
7788 SCOTTAAAAA 3000 20
7902 FORDAAAAA 3000 20
7369 SMITHAAAAA 8000 20
7876 ADAMSAAAAA 1300 20
But I want the output like this
EMPNO ENAME SAL DEPTNO
7566 JONESA 2000 20
7788 SCOTTA 3000 20
7902 FORDA 3000 20
7369 SMITHA 8000 20
7876 ADAMSA 1300 20
how to achieve this.
View 9 Replies
View Related
Jan 21, 2013
I WANT to RETRIEVE all the INFORMATION of DEPT ALONG with TWO EMPLOYEES of each DEPARTMENT.is any OTHER WAY to DO THIS due to performance in Oracle 10g
SELECT *
FROM DEPT D,
(SELECT DEPTNO,
MAX(DECODE(RN,1,ENAME,NULL)) ENAME1,
MAX(DECODE(RN,2,ENAME,NULL)) ENAME2
[code]......
View 6 Replies
View Related
Nov 26, 2010
To find all the employees whose salaries greater than avg(salary) of the department.
Quote
select empname,salary,deptid from salaries t1 where
salary > (select avg(salary) from salaries t2 where t1.deptid = t2.deptid);
Unquote
Its not diplaying all departments
View 14 Replies
View Related
Mar 28, 2013
I used Scott schema.I take 2 blocks ,one block having Deptno,Job and also 1st block is a non database block and Another Block Empno,ename,job,sal,deptno, is a database block,my question is when i enter Deptno,Job then Display Employees Details and also Department name
View 1 Replies
View Related
Feb 16, 2013
i have employee table i want to update salary with all employee 5 percent
View 4 Replies
View Related
Jun 12, 2012
There is a attendance table having structure(empid number,signtime datetime)It has data of attendance of employees:
What is the right sql to show employees detail attendance according to the no of days attendance . i.e.(According to the maximum no of attendance first and so on)
suppose: 3 employees abc,bbc,cca abc has 20 days of attendance ,bbc has 21 days,cca has 19 days..The report like this:
bbc 1/5/12 10:30
abc .....
then
cca
according to the no of attendannce
View 6 Replies
View Related