Sie sind auf Seite 1von 2

1.

write the query hike the employee�s salaries 30% who are working in the Banking
Department.

ans: update emp set salary =(salary+(0.3*salary)) where department ='Banking' ;

2.Increase employee salaries as 1000 where employee first_name last but one letter
end with O

ans : update emp set salary =(salary+1000) where first_name like '%o_' ;

3.Write a query display details whose firstname and lastname contains only 5
letters?

ans :select * from emp where length(first_name)=5 and length(last_name)=5 ;

4.Display the employee details whose experience is more than minimum experience
employee.

ans : select * from emp where ( timestamp '2018-01-01'- joining_date)>( select


min( timestamp '2018-01-01'- joining_date) as exp from emp);

5.Write a query display the last three records in the table.


ans : select * from emp order by employee_id limit 3;

6.Write a query display the maximum salary employee details working under Banking
and Insurance department
ans : select * from emp where salary in (select max(salary) from emp group by
department) and department in ('Banking','Insurance')
select first_name, avg(salary) over(partition by department) from emp

7.What is the usage of indexing.


ans : it is used to increase the performance by fast acessing of record based on
indexes

8.What is the difference between primary key and foreign key.


primary key is a combination of not null and unique apllied to a column while
foreign is reference given to other table to maintain data integrety. foreign key
allows null and duplicate values but not the values other than primary kay
reference values.

9.Write a query to get the first 5 characters from person�s name, if name does not
have 5 characters get their actual name.
ans : select left(first_name,5) from emp where length(first_name)>5 union select
concat_ws(' ',first_name,last_name) from emp where length(first_name)<5
select case when length(first_name)>5 then left(first_name,5) else
concat_ws(' ',first_name,last_name) end from emp1

10.When are we going to use truncate and delete?


ans : truncate removes the schema of a table while delete removes the data which
can be rollbacked and we can apply condition using delete to delete a certain
record .

11.Find What is Wrong in this Query?


SELECT subject_code, AVG (marks) FROM students WHERE AVG(marks) > 75 GROUP BY
subject_code;
ans : aggregate functions cant be used in where clause (WHERE AVG(marks) > 75);

12.What is the difference between Having clause and Where clause


ans : where clause is used to apply condition but having clause is used after
applyin group by only.
the order is select fron where clause, group by clause, having clause, order
by.....

Das könnte Ihnen auch gefallen