Adding, deleting, checking and modifying sql of database
Title 1. Introduction to the database
Department dept database:
product car brand brand database:
employee staff database: (deptid is the foreign key from dept)
customer customer database: (staffid is the foreign key from staff)
product production database: (brandid is the foreign key from brand)
Order database: (There are many foreign keys)
2. SQL preparation for some operations on the database
2.1 单表查询
(1) Query all information of dept
select * from dept ;
(2) Query the department information of number one through dept number deptid=1
select * from dept where dept.deptid = 1;
(3) Query the details of employees whose beginning with "王" and the third last character is "航"
select * from staff where staff.sname like '王%航_';
(4) Query female employees with Qian in the name (Qian appears in any position in the fuzzy query)
select * from staff where staff.sname like '%倩%' and staff.ssex = '女';
(5) Paging: Query the total number of data in the staff database.
select count(*) from staff;
(6) Query each product number and price in the car that exceed the average selling price of all car products
select p1.productid,p1.pout from production p1
where p1.pout>(
select AVG(p2.pout) from production p2
) ;