You are on page 1of 2

SELECT *FROM college;

select * from college where city IN('pune','ahmednager');


UPDATE college set city='nagpur' WHERE cno=103;
UPDATE college set city='Dhule' WHERE cno=107;
select MAX(college.salary) from college;
select MIN(college.salary) from college;
select SUM(college.salary) from college;
select * from college WHERE salary is null;
select COUNT(college.cno) from college;
select * from college order BY college.salary;
SELECT * FROM college ORDER BY college.salary desc;
select count(college.salary)as member from college where salary not between 10000
and 12000;
select count(college.salary)as member from college where salary not between 7000
and 10000;
select count(college.salary)as member from college where salary between 7000 and
10000;
select upper(college.cname) from college;
select lower(college.cname) from college;
select initcap(college.cname) from college;
select ltrim(college.cname) from college;
select rtrim(college.cname) from college;
select length(college.cname) from college;
select count(DISTINCT(college.city)) from college;
select DISTINCT(college.city) from college;
select cno,sum(college.salary) as TotalSal from college GROUP BY cno ;
select * from dept;
select * from emp;
select deptno ,sum(sal) as totalsal from emp group by deptno ;
create table emp1 as(select * from emp);
select * from emp1;
select * from emp MINUS(select * from emp1);
(select * from emp )INTERSECT(select * from emp1);
(select * from emp )UNION(select * from emp1);
select * from emp where sal>=1000 and sal<=2000;
select * from emp where sal BETWEEN 1000 and 2000;

===how to create table using existing table without value====


create table emp2 as select * from emp where 1=2;

==============================
Select * From College;
Select Cno,Sum(College.Salary) As Totalsal From College Group By Cno ;
Select * From Dept;
Select * From Emp;
Select Deptno ,Sum(Sal) As Totalsal From Emp Group By Deptno ;
Create Table Emp1 As(Select * From Emp);
Select * From Emp1;
Select * From Emp Minus(Select * From Emp1);
(Select * From Emp )Intersect(Select * From Emp1);
(Select * From Emp )Union(Select * From Emp1);
Select * From Emp Where Sal>=1000 And Sal<=2000;
Select * From Emp Where Sal Between 1000 And 2000;
Create Table Emp2 As Select * From Emp Where 1=2;
Select * From Emp2;
Drop Table Emp2;
Select Count(Ename) From Emp Where Sal>=3000;
Select * From Emp Where Sal<3000;
select * from emp;
Select * From Emp WHERE Sal>All(Select Sal From Emp Where Sal<3000);
Select * From Emp WHERE Sal>ANY (Select Sal From Emp Where Sal<3000);

select ename,sal,comm,(sal+nvl(comm,0)) as totalsal from emp;


select count(MGR),count(sal) from emp;
select * from emp where ename LIKE'%R';
select * from emp where ename LIKE'S_____';
select * from emp WHERE ename IN('BLAKE','SCOTT','KING','FORD');
select * from emp where job not in('SALESMAN','CLERK');
select * from emp where job in('SALESMAN','CLERK');
select ename,sal/12 as monthlySal from emp;//monthly wise salary of every employee
select * from dept;
--Count the number of employees in department wise
select count(empno),b.deptno,dname from emp a,dept b where a.deptno(+)=b.deptno
group by b.deptno,dname;

select max(rowid) from emp;


select * from emp a where rowid=(select max(rowid) from emp b where
a.empno=b.empno);//distinict employee from emp table
select distinct(job) from emp;
select distinct(empno) from emp;
select count(distinct(sal)) from emp;
select distinct hiherdate from emp a where &n=(select count(distinct(sal) from emp
b where a.sal>=b.sal);//command not run
select distinct sal from emp a where 3>=(select count(distinct sal) from emp b
where a.sal<=b.sal)order by a.sal desc;
select count(distinct sal) from emp a,emp b where a.sal<=b.sal;
select count(distinct(b.sal))from emp a,emp b where a.sal>=b.sal;
select * from emp;
select distinct sal from emp a where 3>=(select count(distinct sal) from emp b
where a.sal>=b.sal);
select distinct(b.sal) from emp a,emp b where a.sal>=b.sal;
select sal from emp order by sal desc 5,0;
select max(sal) from emp;
select max(sal) from emp where sal not in(5000);
select max(sal) from emp where sal not in(select max(sal) from emp);

select * from emp where sal=(select max(sal) from emp where sal>(select max(sal)
from emp));
select max(sal) from emp where sal<(select max(sal) from emp);
select min(sal) from emp where sal=(select min(sal) from emp);
select * from emp where sal=(select min(sal) from emp);

select * from emp where sal=(select max(sal) from emp where sal<(select max(sal)
from emp));
select * from emp where sal=(select min(sal) from emp where sal>(select min(sal)
from emp));
select TOP 4 * from emp;
select *from emp where rownum<=3;

You might also like