Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
MySQL Queries

MySQL Queries

Ratings:

4.0

(2)
|Views: 366|Likes:
Published by Bhavin Acharya

More info:

Published by: Bhavin Acharya on Oct 19, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Nth salary :

select sal
from emp a
where &n=(select count(sal)

from emp b
where a.sal<=b.sal);
FOR DELETING DUPLICATE ROWS
delete from <table_name> a
where rowid not in(select max(rowid)
from <table_name> b
where a.column_name=b.column_name;
Max two salaries :

select sal
from emp a
where &n >= (select count ( sal)

from emp b
where a.sal <= b.sal);
count dulicate vales:

select sal,count(sal)
from emp
group by sal
having count(sal)>1 ;

Max or min average salary with
depatment ID:

select deptno,avg(sal)
from emp
group by deptno
having avg(sal)= (select min(avg(sal))

from emp
group by deptno);
second highest max salary

select max(sal)
from emp
where sal < (select max(sal)

from emp);
Details of highest salary earner

select *
from emp
where sal = (select max(sal)

from emp);
Details of lowest salary earner

select *
from emp
where sal = (select min(sal)

from emp)
Using Group by

select deptno,sum(sal)
from emp
group by deptno;

Using Order by
select * from emp
order by sal;
DISTINCT
select distinct(job)
from emp;
Counts

select job, count(job)
from emp
group by job;

Table Structure
desc orders
Creation of table
create table orders (sal number,lastname
varchar2(10));
Insertion of records
insert into orders values (&sal,'&lastname');
Adding Column to Table
alter table orders add (job varchar2(10) );
To Modify Column Definition
alter table orders modify (job number);
To Drop a Column from a Table
alter table orders drop column job;
To Unused a Column
alter table orders set unused (firstname);
Using NVL Function (Replaces Null
value with given value)
select empno, ename, sal,nvl (comm, 200)
from emp;

select ename, sal,
nvl(to_char(comm),'commission not payed')
from emp;

SELECT ABS(10) FROM DUAL;
ABS(10)
----------
10
SELECT LEAST(4,7,3,5,9,2) FROM DUAL;
LEAST(4,7,3,5,9,2)
------------------
2
SELECT GREATEST(4,7,3,5,9,2) FROM
DUAL;
GREATEST(4,7,3,5,9,2)
---------------------
9
SELECT TRUNC(1.23456,3) FROM DUAL;
TRUNC(1.23456,3)
----------------
1.234
SELECT TRUNC(1.23456) FROM DUAL;
TRUNC(1.23456)
--------------
1
SELECT SQRT(9) FROM DUAL;
SQRT(9)
----------
3
SELECT ROUND(1.23456,3) FROM
DUAL;
ROUND(1.23456,3)
----------------
1.235
SELECT ROUND(1.23456) FROM DUAL;
ROUND(1.23456)
--------------
1
SELECT POWER(10,2) FROM DUAL;
POWER(10,2)
-----------
100
SELECT MOD(10,3) FROM DUAL;
MOD(10,3)
----------
1
SELECT LOG(100,10) FROM DUAL;
LOG(100,10)
-----------

.5
SQL> SELECT LOG(10,100) FROM DUAL;
LOG(10,100)

-----------
2
SELECT LN(10) FROM DUAL;
LN(10)
----------
2.30258509
SELECT FLOOR(123.456) FROM DUAL;
FLOOR(123.456)
--------------
123
SELECT ABS(-10) FROM DUAL;
ABS(-10)
----------
10
SELECT CEIL(123.456) FROM DUAL;
CEIL(123.456)
-------------
124
To diplay those departments which have more
than 5 employees in them we can write.
SELECT DEPTNO, COUNT(*)
FROM EMP
GROUP BY DEPTNO
HAVING COUNT(*) > 5 ;

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Erwin Blas liked this
Syed Sohaib Ali liked this
jfscrbd liked this
anoobhamza2002 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->