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

create table

The document contains SQL commands for creating and manipulating tables for students, customers, courses, and teachers. It includes operations such as inserting data, selecting records, updating entries, and deleting records, along with aggregate functions and group by clauses. Additionally, it demonstrates altering table structures by adding and dropping columns, as well as renaming columns.

Uploaded by

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

create table

The document contains SQL commands for creating and manipulating tables for students, customers, courses, and teachers. It includes operations such as inserting data, selecting records, updating entries, and deleting records, along with aggregate functions and group by clauses. Additionally, it demonstrates altering table structures by adding and dropping columns, as well as renaming columns.

Uploaded by

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

create table student(

rollno int primary key,


name varchar(50),
marks int not null,
grade varchar(1),
city varchar(20)
);
select * from student;
insert into student values
(101,'anil',85,'B','kosamba'),
(102,'Bhumika',91,'A','Anand'),
(103,'Chetan',85,'B','Delhi'),
(104,'Dhruv',96,'A','Delhi'),
(105,'emanuel',12,'F','Delhi'),
(106,'Farah',82,'B','Mumbai');

select name,marks from student;


select distinct city from student;
select * from student where marks>80;
select * from student where city='Mumbai';

select * from student


where city = 'Mumbai' and marks>80;

select * from student where marks + 10>100;


select * from student
where city='kosamba' or marks>80;

select * from student


where marks between 80 and 90;

select * from student


where city in ('Delhi','Mumbai');

select * from student


where city not in ('Delhi','Mumbai');

select * from student


where marks > 75
limit 3;

select * from student


order by city asc;
select * from student
order by marks desc
limit 3;

----Aggregate Fuction----
--MAX--
select max(marks) from student;
--MIN--
select min(marks) from student;
--AVGERAGE--
select avg(marks) from student;
--COUNT--
select count(marks) from student;
--SUM--
select sum(marks) from student;

--Group by clause--
select city ,count(name)
from student
Group by city;

select city ,avg(marks)


from student
Group by city
order by city;

select grade,count(name)
from student
group by grade;

create table customer(


customer_id int primary key,
customer varchar(20),
mode varchar(20),
city varchar(20));

insert into customer values(


101,'Olivia Barrett','Netbanking','Portland'),
(102,'Ethain Sindair','Credit Card','Miami'),
(103,'Maya Hemandez','Credit Card','Seattle'),
(104,'Liam Donovan','Netbanking','Denvar'),
(105,'Sophia Nguyen','Credit Card','New Orideans'),
(106,'Caieb Foster','Debit Card','Mineapoils'),
(107,'Ava Patel','Debit Card','Pheonix'),
(108,'Lucas Carter','Netbanking','Boston'),
(109,'Isabella Marlinez','Netbanking','Nashville'),
(110,'Jackson Brooks','Credit Card','Boston');
Select * from customer;

select mode, count(customer)


from customer
group by mode;

--- Having Clause---


select city, count(name)
from student
group by city
having max(marks)>90;

---Update---
update student
set grade = 'O'
where grade = 'A';

select * from student;

update student
set marks = 86
where rollno = 105;

update student
set grade = 'B'
where marks between 80 and 90;
select * from student;

update student
set marks = marks +1;

--Delete--
insert into student values
(107,'Yong',20,'F','Pune'),
(108,'heer',16,'F','Kosamba')
select * from student;

delete from student


where marks <= 33;

select * from student


order by marks;

create table course(


id int primary key,
name varchar(10));

insert into course values


(101,'Science'),
(102,'English'),
(103,'Hindi'),
(104,'Computer'),
(105,'Maths');

select * from course;

create table teacher(


id int primary key,
name varchar(20),
course_id int);

insert into teacher values


(101,'Adan',101),
(102,'Mangala',103),
(103,'Rupal',102),
(104,'Donald',105),
(105,'Vipul',104);
select * from teacher;

alter table student


add column age int ;

select * from student;

alter table student


drop column age;

alter table student


rename name to stud_name;

select * from student;

You might also like