Sei sulla pagina 1di 4

FINTELLIX WRITTEN TEST

FCT_EMPLOYEE

Periodid(pk) Id(PK) salary Working hours cityid


20150131 1001 50000 120 1
20150131 1002 15000 180 2
20150131 1003 53000 120 3
20150131 1004 52000 120 4
20150131 1005 51000 120 5
20150131 1006 53000 120 6
20150131 1007 55000 120 7
20150131 1008 54000 120 8
20150131 1009 56000 120 Null
20150228 1001 56000 120 1
20150228 1002 57000 120 2
20150228 1003 58000 120 3
20150228 1004 59000 120 4
20150228 1005 60000 120 5
20150228 1008 59000 120 8
20150228 1009 57000 120 9
20150228 1010 59000 120 1
20150331 1001 60000 120 2
20150331 1002 55000 125 5
20150331 1003 61000 120 3
20150331 1004 61000 110 4
20150331 1005 61000 120 5
20150331 1006 61000 115 4
20150331 1007 61000 130 2
20150331 1008 62000 120 8
20150331 1009 62000 120 9
20150331 1010 63000 120 1
20150331 1011 63000 120 9

DIM_CITY

ID

NAME

ID(pk)

STATEID
DIM_STATE

ID(pk)

NAME

DIM_ EMPLOYEE

ID(pk) Name Grade

1001 AA A

1002 BB B

1003 CC C

1004 DD D

1005 EE E

SQL Query

1. Find out average of salary, grade for the period id 20150131.

select avg(sal),grade

from fct_emp fe,dim_emp de

where fe.id=de.id and period_id=20150131

group by grade;

2. Find out City wise maximum, minimum, average salary of employee for the period id 20150131.

select name,max(sal),min(sal),avg(sal)

from fct_emp fe,dim_city dc

where fe.city_id=dc.id

and period_id=20150131

group by name;

3. Find out number of employees resigning per month.\


select count(*) from

select id from dim_emp

minus

select (a-1+level)miss from

(select min(id)a,max(id)b from fct_emp where period_id=&n)

connect by level<=b-a+1

);

4. Find out percentage of increase of average salary in given month.

select ((avg(sal)/sum(sal))*100) as percent_increase from fct_emp

where period_id=&n

group by period_id;

5. Month by Month, grade wise top 2 average increase in salary for the period id 20150131 and 20150228.

SELECT * FROM

(SELECT PERIOD_ID,to_char(to_date(period_id,'yyyy-mm-dd'),'mon'),GRADE,AVG(SALARY) OVER (PARTITION BY


GRADE ORDER BY SALARY),DENSE_rank() OVER(PARTITION BY GRADE ORDER BY SALARY) R FROM FCT_EMP
F,DIM_EMP D WHERE F.ID=D.ID)

WHERE R<=2

AND PERIOD_ID IN (20150131,20150228);

6. Find out Grade wise, State wise Maximum salary.

select ds.name,grade,max(sal)

from dim_state ds,dim_city dc,fct_emp fe,dim_emp de

where de.id=fe.id

and ds.id=dc.state_id

and dc.id=fe.city_id
group by ds.name,grade;

7. Display the output like this

GRADE Max SAL

select grade,max(salary)

from fct_emp f,dim_emp d

where f.id=d.id

group by grade

order by (case grade when 'B' then 0

when 'C' then 1

when 'A' then 2

when 'D' then 3

when 'E' then 4

end);

Data Model

8. Change the structure of model to add pin code and address to the employee table. It should accept whatever
the address may be even multiple addresses.

9. Change structure of the model to add department number in the employee table. There should be a facility to
add more than one department number to an employee table. The percentage of cardinality of working should
not exceed 100%.

Potrebbero piacerti anche