Adding, deleting, checking and modifying sql about the database (take the Wuhan Auto Capital Management System project I did recently as an example)

Adding, deleting, checking and modifying sql of database

Title 1. Introduction to the database

Department dept database:
Insert picture description here
product car brand brand database:
Insert picture description here
employee staff database: (deptid is the foreign key from dept)
Insert picture description here
customer customer database: (staffid is the foreign key from staff)
Insert picture description here
product production database: (brandid is the foreign key from brand)
Insert picture description here
Order database: (There are many foreign keys)
Insert picture description here

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
) ;

Guess you like

Origin blog.csdn.net/qq_43479839/article/details/104714146