Write a query to display the no.Of people with the same job
select job, count(job) from emp group by job;
Code
SELECT count(*), job FROM emp GROUP BY job
select last_name,hiredate,to_char(hiredate,'day') day
eg. if use scott/tiger schema:
select ename, TO_CHAR(hiredate, 'DAY') as DAY from emp;
What is the difference between replace and translate
Answered by: Saumendra Mohanty
Answered On : May 16th, 2006Both Replace and Translate are single row functions in Oracle 9i.
The Replace Function replaces single character with multiple characters.
But in Translate Function replaces sinlge character with sinlge character only.
The Replace Function can replace the old substring whose length are not same to the length of new substring. (length of newsub DONT NEED eaqual tolength of oldsub ) But in Translate Function only can...
It is used to replace one string with another string, and
translate used to translate one character to another char.
What is the diffrence between and constraints and triggers?
Check constraints it cant work multiple tables
Constraints and triggers are both used to enforce business rules at the database level. Constraints are primary key, unique key, foreign key, not null contraints etc, while triggers can be defined at the database and table level to do certain tasks depending on data entered
Find out nth highest salary from emp table
Select distinct (a.Sal) from emp a where &n = (select count (distinct (b.Sal)) from emp b where a.Sal < = b.Sal);for eg:-enter value for n: 2sal---------3700
This will work for only highest salary n=1 but not work for 2nd and rest nth salary...
Did you have tried this?
Code
SELECT * FROM (SELECT employee_id, salary, dense_rank() OVER ( ORDER BY salary DESC) r FROM employees) a WHERE a.r =3 ;
Using pivot option in SQL server 2008.
by using decode function