0% found this document useful (0 votes)
13 views6 pages

Dbms 3

this is a program sheet of creating a data base using mysql
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Dbms 3

this is a program sheet of creating a data base using mysql
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Shwetank Pandey, 2301420042 ,b.

tech cse
create database sp;
use sp;

create table Departement( Deptno int primary key


,Dname varchar(15) not null);
insert into Departement values
(40,"OPERATION");
SELECT * FROM Departement;
create table employee( empno int (4)primary key,
ename varchar(20) not null, job varchar(20),mgr
int(4), herdate Date ,sal int(10) ,comm int(7),
Deptno varchar(2) );

ALTER TABLE Departement


MODIFY COLUMN Deptno VARCHAR(2);

ALTER TABLE employee


CHANGE COLUMN herdate hiredate DATE;

ALTER TABLE employee


ADD CONSTRAINT fk_Deptno
FOREIGN KEY (Deptno)
REFERENCES Departement(Deptno);

TRUNCATE TABLE employee;

INSERT INTO employee (empno, ename, job,


mgr, hiredate, sal, comm, deptno) VALUE
(7788, 'SCOTT', 'ANALYST', 7566, '1982-12-09',
3000, NULL, '40'),
(7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800,
NULL, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, '1981-02-20',
1600, 300, 30),
(7521, 'WARD', 'SALESMAN', 7698, '1981-02-22',
1250, 300, 30),
(7566, 'JONES', 'MANAGER', 7839, '1981-04-02',
2975, NULL, 20),
(7654, 'MARTIN', 'SALESMAN', 7698, '1981-09-
28', 1250, 1400, 30),
(7698, 'BLAKE', 'MANAGER', 7839, '1981-05-01',
2850, NULL, 30),
(7782, 'CLARK', 'MANAGER', 7839, '1981-06-09',
2450, NULL, 20),
(7839, 'KING', 'PRESIDENT', NULL, '1981-11-17',
5000, NULL, 20),
(7844, 'TURNER', 'SALESMAN', 7698, '1981-09-
08', 1500, 0, 30),
(7876, 'ADAMS', 'CLERK', 7788, '1983-01-12',
1100, NULL, 20),
(7900, 'JAMES', 'CLERK', 7698, '1981-12-03', 950,
NULL, 30),
(7902, 'FORD', 'ANALYST', 7566, '1981-12-03',
3000, NULL, 20),
(7934, 'MILLER', 'CLERK', 7782, '1982-01-23',
1300, NULL, 10);

select * from Departement;


select * from employee;
--------------------
select * from employee
where job = 'salesman' or comm>300;

select deptno from employee;


select distinct deptno from employee;

select sum(sal) as sumsalary from employee


where job = 'manager';

select min(sal ) as minsalary , max(sal) as maxsalary;

select count(empno) as empnocount from employee


where job= 'manager';

select count(empno) as empnocount, sum(sal) as


sumsalary
from employee where job= 'manager';

select deptno , count(empno) as countemp ,sum(sal) as


sumsalary
from employee
group by deptno;

select deptno , count(empno) as countemp ,sum(sal) as


sumsalary
from employee
group by deptno having count(empno)>1 order by
deptno;

select job,count(*) from employee group by job order by


count(*) desc;
select job, sum(sal),max(sal),min(Sal),avg(sal)
from employee group by job
having avg(sal)>1000;

select job,sum(sal) from employee group by job;

select deptno,count(empno) from employee


group by deptno;

SELECT job, COUNT(*) AS empn


FROM employee
GROUP BY job;

SELECT job, SUM(sal) AS total_salary


FROM employee
GROUP BY job;

SELECT deptno, COUNT(*) AS total_employees


FROM employee
GROUP BY deptno
HAVING COUNT(*) > 3;
SELECT deptno, MAX(sal) AS max_salary
FROM employee
GROUP BY deptno;

SELECT job, SUM(sal) AS total_salary


FROM employee
GROUP BY job
HAVING SUM(sal) > 40000;

SELECT job, COUNT(*) AS total_employees


FROM employee
GROUP BY job
HAVING COUNT(*) > 3;

You might also like