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

SQL 1

The document provides SQL commands for creating and populating two tables, 'trainer' and 'course', with various attributes and values. It includes several SQL queries to display trainer information, filter by hire dates, and aggregate data based on specific conditions. The queries cover displaying trainer details, counting trainers by city, and calculating course fees under certain criteria.

Uploaded by

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

SQL 1

The document provides SQL commands for creating and populating two tables, 'trainer' and 'course', with various attributes and values. It includes several SQL queries to display trainer information, filter by hire dates, and aggregate data based on specific conditions. The queries cover displaying trainer details, counting trainers by city, and calculating course fees under certain criteria.

Uploaded by

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

#to create table

mysql>create table trainer (TID int(3) primary key , Tname varchar(20) NOTNULL ,
CITY varchar(20) NOTNULL , HIRE_DATE date , SALARY int(5) NOTNULL);

#to insert values


mysql>(101,'Sunanya','Mumbai','1998-10-15',90000),
(102,'Anamika','Delhi','1994-12-24',80000),
(103,'Deepti','Chandigarh','2001-12-21',82000),
(104,'Minaskshi','Delhi','2002-12-25',78000),
(105,'Richa','Mumbai','1996-01-12',95000),
(106,'Maniprabha','Chennai','2001-12-12',69000);

#other table
mysql>create table course(CID varchar(5),Cnamevarchare(20) notnull,FEES
int(5),Startdate Date,TID int(3));
mysql>insert into course values
('c201','AGDCA',12000,'2018-07-02',101),
('c202','ADCA',15000,'2018-07-15',103),
('c203','DCA',10000,'2018-10-01',102),
('c204','DDTP',9000,'2018-09-15',104),
('c205','DHN',20000,'2018-07-25',105),
('c206','DLEUFL',18000,'2018-08-01',101);

1 to 4:
1)to display the trainername,city and salary in decending orderof the hiredate:
select Tname,CITY,SALARY from TRAINER order by hiredates desc;
2)to display hire_date ,tname and city of trainer who joined in dec-2001:
select Tname,CITY from TRAINER where HIRE_DATE like '2001-12-%';
3)to display HIRE_DATE,tname,startdate from TABLE TRAINER and course for all the
course with fee<=10000:
select HIRE_DATE,Tname,STARTDATE from TRAINER,COURSE WHERE FEES<=10000 AND
TRAINER.ID=COURSE.ID
4)TO DISPLAY NO.OF TRAINER FROM EACH CITY:
SELECT CITY,COUNT(*) FROM TRAINER GROUP BY CITY;

5 TO 8
5)SELECT TID,Tname FROM TRAINER WHERE CITY NOT IN ('Delhi','Mumbai');
6)SELECT DISTINCT TID FROM COURSE;
7)SELECT TID,COUNT(*),MIN(FEES) FROM GROUP BY TID HAVING COUNT(*)>1;
8)SELECT COUNT(*),SUM(FEES) FROM COURSE WHERE STARTDATE <'2018-09-15';

You might also like