0% found this document useful (0 votes)
18 views

Some Python SQL Queries

Uploaded by

motorehan1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Some Python SQL Queries

Uploaded by

motorehan1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

• Some Python sql queries.

•1.Create
and open Database named MYORG.
Ans: Create database MYORG;

2. Open Database named MYORG.


Ans: Use MYORG;

3.Write commands to display the system date.


Ans: select sysdate;

4.Write a query to find out the result of 63.


Ans: select pow(6,3);
5.Write command to show the Tables in the MYORG Database.
Ans: Use MYORG;
Show tables;
DEPT

6.Add one column State of data type VARCHAR and size 30 to table DEPT
Ans: alter table DEPT
Add(state varchar(30));
7.Create a table name EMP with following structure

Ans: create table emp


(EmpID integer primary key,
EmpName varchar(30) not null,
Designation char(10),
DOJ date,
Sal integer check(sal>1000),
Comm integer,
DeptID integer,
Foreign key(DeptID) references DEPT(DeptID) );

EMP

8.Insert the first record in table emp.


Ans: insert into emp
Values(8369,’SMITH’,’CLERK’,’18-12-1990’,800,200,10);
9.Write a query to display EmpName and Sal of employees whose salary are greater
than or equal to 2200
Ans: select empname, sal
from emp
where sal>=2200;
10.Write a query to display details of employees who are not getting commission.
Ans: select *
from emp
where comm is NULL;
11.Write a query to display employee name and salary of those employees who don’t
Have their salary in range of 2500 to 4000.
Ans: select empname, sal
From emp
Where sal not between 2500 and 4000;

12.Write a query to display the name of employee whose name contains “A” as third
alphabet in Ascending order of employee names.
Ans: select empname
From emp
Where empname like “__A%”
Order by empname;
13.Display the sum of salary and commission of employees as “Total Incentive” who
are getting commission .
Ans: select sal+comm As “Total Incentive”
From emp
where comm is not NULL;
14.Show the average salary for all departments with more than 5 working people.
Ans: select avg(sal)
From emp
Group by deptid
Having count(*)>5;
15.Display the distinct designation offered by the Organization.
Ans: select distinct designation
From emp;
16.List the count of Employees grouped by DeptID.
Ans: select count(*)
From emp
Group by DeptID;
17.Display the names of employees who joined on or after 01/05/1991.
Ans: Select empname
From emp
Where DOJ>=’01/05/1991’;
18.Display the employee records in order by DOJ.
Ans: select *
From emp
Order by DOJ;
19.Display the maximum salary of employees in each Department.
Ans: select max(sal)
From emp
Group by department;
20.Update all the records as add ‘Mr.’ with EmpName.
Ans: update emp
Set EmpName=concat(‘Mr’,EmpName);
21.Display the name of Employees who is working in SALES department.
Ans: select empname
From emp, dept
Where deptName=”SALES” and emp.DeptID=dept.DeptID;
22.Drop the emp table.
Ans: drop table emp;
23.Delete all the records who is working as “CLERK”
Ans: delete from emp
Where designation=”CLERK”;
24.Show the minimum, maximum and average salary of Managers.
Ans: select min(sal), max(sal), avg(sal)
From emp
Where designation=”Manager”;
25.Increase the salary of managers by 15%.
Ans: update emp
Set sal= sal + 0.15*sal
Where designation=”Manager”;
26.To display the name of those employees whose location is Delhi.
Ans: select empname
From emp, dept
Where location=”Delhi” and emp.DeptID=dept.DeptID;
27.To display total salary of employees of sales department.
Ans: select sum(sal)
From emp, dept
Where deptName=”SALES” and emp.DeptID=dept.DeptID;
28.To show details of employees who joined before ‘01/04//1995’.
Ans: select *
From emp
Where DOJ<’01/04/1995’;
29.Delete all the records who is working as “SALESMAN” and salary more than 1500.
Ans: delete from emp
Where designation=” SALESMAN” and sal>1500;
30.Set the commission as 100 who are not getting any commission.
Ans: update emp
Set comm= 100
Where comm Is NULL;

You might also like