0% found this document useful (0 votes)
27 views4 pages

Dbms Practice

The document contains SQL commands to create tables, insert data, and perform queries on tables related to student marks, employees, orders, and customers. Tables are created with various data types for columns. Data is inserted into the tables. Joins and various clauses like WHERE, GROUP BY, ORDER BY, LIMIT are used to query and filter the data.

Uploaded by

ayushyadav73095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Dbms Practice

The document contains SQL commands to create tables, insert data, and perform queries on tables related to student marks, employees, orders, and customers. Tables are created with various data types for columns. Data is inserted into the tables. Joins and various clauses like WHERE, GROUP BY, ORDER BY, LIMIT are used to query and filter the data.

Uploaded by

ayushyadav73095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

-- marks

create table marks


(
name varchar(20),
m1 int(10),
m2 int(10),
m3 int(10),
roll_no int(20)
);
-- desc marks;
insert into marks values('sasaram',97,67,85,1),('Chraas',84,97,65,2),
('subham',54,47,65,3),('Chrs',24,67,05,4),('Chri',14,57,95,5),('Cris',90,77,85,6),
('C',78,68,64,7);
/*select * from marks;
select * from marks where m1 = 54;
select name from marks where name='c';
select name from marks where name='c';
select name,roll_no from marks where m1=97;
select * from marks where m1<=60;
select * from marks where m1<>97;
select * from marks where m1>m3;*/

-- employee

create table employee


(
emp_id int(10),
name varchar(20),
salary int(10),
purchase_year date,
age int
);
desc employee;
insert into employee values(001,'John',10000,'2004/12/03',17),
(009,'Robert',9000,'2003/12/03',19),(008,'James',12000,'2003/12/03',22),
(007,'ankit',13000,'2004/02/5',23),(003,'Michael',55000,'2014/4/6',25),
(0041,'David',50000,'2008/02/14',27),(011,'William',60000,'2009/02/5',29),
(012,'Richard',70000,'2012/02/5',28),(004,'Joseph',20000,'2010/02/5',30);
delete from employee where purchase_year ='2014-04-06';
delete from employee where emp_id = 009;
delete from employee;
select * from employee where salary>=10000;
select * from employee where age>23 and salary>=20000;

/*-- create
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept TEXT NOT NULL,
salary int(10),
gender varchar(30),
hire_year int(10)
);
*/
-- PRACTICAL NO-4
/*INSERT INTO EMPLOYEE VALUES (0001, 'Clark', 'Sales',20000,'male',2022),(0002,
'Dave', 'Accounting',30000,'male',2020-09-28),(0003, 'Ava',
'Sales',25000,'female',2022-10-16),(0004, 'SAva', 'computer
science',32000,'female',2022-10-04);
select name,salary from EMPLOYEE;
select * from EMPLOYEE order by salary desc;
select * from EMPLOYEE limit 2;
select sum(salary) as total_salary from EMPLOYEE where dept='sales';
select avg(salary) as average_salary from employee where dept='sales';
select count(*) as total_employees from EMPLOYEE where dept='sales';
select min(salary) as minimum_salary from EMPLOYEE where gender='female';
select min(salary) as minimum_salary from EMPLOYEE where hire_year='2022'
-- same use max at place of min for maximum*/

-- PRACTICLE N0-5
/*select lower('AYUSH YADAV');
select upper('ayush yadav');
select left('thakur college of cience and commerce',6);
select right('thakur college of cience and commerce',8);
select mid('thakur college of science and commerce',8,31);
select ltrim(' ayush');
select rtrim('ayush ');
select reverse('thakur college of cience and commerce');
select concat('its',' ','an',' ','dbms',' ','practicle');
select abs(-2465436);
select round(64.562543,0);
select mod(3,10); -- remainder
select pow(2,5);
select sqrt(16);
select day('2002-12-12');
select month('2002-12-12');
select year('2002-12-12');
select dayname('2002-12-12');
select monthname('2002-12-12');
select now();*/

create table marks


(
roll_no int(10),
first_name varchar(30),
sur_name varchar(30),
m1 int(10),
m2 int(10),
m3 int(10)
);

insert into marks values(1836,'ayush','yadav',19,18,17),


(1838,'anshika','yadav',10,19,15),(1846,'amir','yadav',20,17,15),
(1867,'suresh','yadav',13,12,11),(1856,'karan','yadav',18,18,18),
(1852,'roshan','yadav',19,08,07);
select upper(first_name),lower(sur_name) from marks;
select first_name,left(first_name,2),right(first_name,3),mid(first_name,3,2) from
marks;
select first_name,reverse(first_name) from marks;

-- PRACTCLE NO-6
create table marks
(
roll_no int(10),
first_name varchar(30),
sur_name varchar(30),
m1 int(10),
m2 int(10),
m3 int(10),
target int(20),
zone varchar(20)
);

insert into marks values(1836,'ayush','yadav',19,18,19,33000,'western'),


(1838,'anshika','yadav',10,19,15,18000,'eastern'),
(1846,'amir','yadav',20,17,15,25000,'western'),
(1867,'suresh','yadav',13,12,11,30000,'eastern'),
(1856,'karan','yadav',18,18,18,22000,'western'),
(1852,'roshan','yadav',19,08,07,19000,'eastern');
select * from marks where m1=any(select m3 from marks );
select * from marks where target>(select avg(target) from marks);
select roll_no,first_name,sur_name from marks where target=(select max(target) from
marks);
select first_name,sur_name from marks where zone= any(select zone from marks where
zone='western');

-- PRACTICLE NO-7

create table orders


(
order_id int(10),
order_date date,
customer_id int(10),
product_id int(10)
);

create table customers


(
customer_id int(10),
customer_name varchar(20)
);

insert into orders values(1,'2023-10-10',101,201),(2,'2023-10-12',102,202),


(3,'2023-10-15',103,203);
insert into customers values(101,'john doe'),(102,'jane smith'),(103,'michael
johnson');

select orders.order_id,orders.order_date,customers.customer_name
from orders
inner join customers
on orders.customer_id=customers.customer_id;

select o.order_id,o.order_date,c.customer_name
from orders o
inner join customers c
on o.customer_id=c.customer_id;

select orders.order_id,orders.order_date,customers.customer_name
from orders
inner join customers
on orders.customer_id=customers.customer_id
and orders.order_date>'2023-10-10';

select orders.order_id,orders.order_date,customers.customer_name
from orders
left join customers
on orders.customer_id=customers.customer_id;

select orders.order_id,orders.order_date,customers.customer_name
from orders
right join customers
on orders.customer_id=customers.customer_id;

You might also like