当前位置:网站首页>Crud of MySQL
Crud of MySQL
2022-07-24 06:29:00 【zsm030616】
One , Basic additions and deletions
(SQLServer And PLSQL The statements are basically the same )
Be careful : however "+" stay MySQL The plus sign inside does not make splicing , Just do arithmetic
select * from t_student
desc t_student
insert into t_student values('01' , ' Zhao Lei ' , '1990-01-01' , ' male ');
-- Fuzzy query
select * from t_student where sname=' Zhao Lei '
update t_student set sname='xi' where sid='01'
DELETE * FROM t_student where sid = '01';
Two , Case presentation
Case study 1: Query the employee name and bonus rate without bonus
SELECT
last_name,
commission_pct
FROM
t_mysql_employees
WHERE
commission_pct IS NULL;
Case study 1: Check the name and bonus rate of employees with bonus
SELECT
last_name,
commission_pct
FROM
t_mysql_employees
WHERE
commission_pct IS NOT NULL;
Case study 2: Query salary as 12000 Employee information
SELECT
last_name,
salary
FROM
t_mysql_employees
WHERE
salary <=> 12000;
Add filter criteria and sort
Case study : Check department number >=90 Employee information , And in descending order of employee number
SELECT *
FROM t_mysql_employees
WHERE department_id>=90
ORDER BY employee_id DESC;
3、 Sort by expression
# Case study : Query employee information In descending order of annual salary
SELECT *,salary*12*(1+IFNULL(commission_pct,0))
FROM t_mysql_employees
ORDER BY salary*12*(1+IFNULL(commission_pct,0)) DESC;
4、 Sort by alias
Case study : Query employee information In ascending order of annual salary
SELECT *,salary*12*(1+IFNULL(commission_pct,0)) Annual salary
FROM t_mysql_employees
ORDER BY Annual salary ASC;
5、 Sort by function
Case study : Query employee name , And in descending order of the length of the names
SELECT LENGTH(last_name),last_name
FROM t_mysql_employees
ORDER BY LENGTH(last_name) DESC;
6、 Sort by multiple fields
Case study : Query employee information , It is required that the salary be in descending order first , Press again employee_id Ascending
SELECT *
FROM t_mysql_employees
ORDER BY salary DESC,employee_id ASC;
design sketch
Case a :
Case 2 
Case three :

3、 ... and , Sort expansion
1. Expand one
Code demonstration 1
1. Check the employee's name, department number and annual salary , In descending order of annual salary Ascending by name
SELECT last_name,department_id,salary*12*(1+IFNULL(commission_pct,0)) Annual salary
FROM t_mysql_employees
ORDER BY Annual salary DESC,last_name ASC;
design sketch 1
Code demonstration 2
2. The choice of salary is not in 8000 To 17000 The name and salary of the employee , In descending order of wages
SELECT last_name,salary
FROM t_mysql_employees
WHERE salary NOT BETWEEN 8000 AND 17000
ORDER BY salary DESC;
design sketch 2
Code demonstration 3
3. Query mailbox contains e Employee information , And first by the number of bytes in the mailbox , And then in ascending order by department number
SELECT *,LENGTH(email)
FROM t_mysql_employees
WHERE email LIKE '%e%'
ORDER BY LENGTH(email) DESC,department_id ASC;
design sketch 3
2. Development 2
《 Correlation table 》
Code demonstration 1
-- User table
CREATE TABLE tb_user(
user_id VARCHAR(15) NOT NULL,
order_time datetime not null,
order_category VARCHAR(20) not null,
order_amt float not null,
shop_id VARCHAR(50) not null
)
insert into tb_user VALUES('D890','2018-01-06 12:34:00',' skewer ',18.90,'ZL123');
insert into tb_user VALUES('D890','2018-02-07 12:34:00',' Hamburger ',19.50,'SM456');
insert into tb_user VALUES('B456','2018-03-06 12:34:00',' Chicken wings ',10.30,'ZL123');
insert into tb_user VALUES('B456','2018-04-01 12:34:00',' Spicy Hot Pot ',25.30,'HBW123');
insert into tb_user VALUES('C789','2018-05-09 12:34:00',' Spicy Hot Pot ',15.78,'XM456');
-- Merchant list
CREATE TABLE tb_db(
shop_id VARCHAR(15) NOT NULL,
db_name VARCHAR(20),
db_team VARCHAR(20),
START_time datetime,
END_time datetime
)
insert into tb_db VALUES('ZL123',' Xiao Ming ',' sales A Group ','2018-01-01','2015-01-14');
insert into tb_db VALUES('ZL123',' Xiao Zhang ',' sales A Group ','2016-01-15','2018-01-17');
insert into tb_db VALUES('SM456',' Xiao Zhang ',' sales B Group ','2016-01-17','2016-01-16');
insert into tb_db VALUES('HBW123',' Xiao Deng ',' sales B Group ','2015-01-01','2017-01-14');
insert into tb_db VALUES('HBW123',' petty thief ',' sales C Group ','2015-01-01','2018-01-15');
insert into tb_db VALUES('XM456',' Xiao Chen ',' sales C Group ','2017-01-01','2019-01-14')
design sketch 1
Code demonstration 2
-- The number of people who only ate spicy hot and hamburgers in January
select count(*) from(
select count(*) from(
select * from (
select * from tb_user where order_time like '%-01-%'
) c where order_category=' Spicy Hot Pot ' or order_category=' Hamburger '
) d GROUP BY user_id HAVING COUNT(*)=2
) e
design sketch 2
Code demonstration 3
-- Calculate each BD_team Of bd Sales of the corresponding stores
select SUM(order_amt) from tb_db a, tb_user b where a.shop_id=b.shop_id GROUP BY a.db_team
design sketch 3
边栏推荐
- Do not rent servers, build your own personal business website (4)
- IP课笔记(4)
- Install Apache manually
- Do not rent a server, build your own personal business website (how to buy a domain name)
- List of problems in the re disk guidance of the project
- 【251】常见的测试工具
- Summary of ten common vulnerabilities (principle, harm, defense)
- 三分钟记住20道性能测试经典面试题
- Simple three-step fast intranet penetration
- LVM与磁盘配额
猜你喜欢
随机推荐
LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
Do not rent servers, build your own personal business website (2)
IP job (2) rip
Ia class summary (1)
leetcode剑指offer jz5 替换空格字符串
Leetcode sword finger offer jz42 maximum sum of continuous subarrays
Remember to get the password of college student account once, from scratch
Unity (III) three dimensional mathematics and coordinate system
leetcode 不用加减乘除算加法 || 二进制中1的个数
【251】常见的测试工具
IA课总结(2)
Ia class summary (2)
[222] memory overflow and location
IP notes (11)
Unity 3D frame rate statistics script
Life warning Maxim
MySQL from basic to entry to high availability
一个测试经理/测试主管/测试总监的工作总结
Leetcode does not add, subtract, multiply, divide, and calculate the number of 1 in binary
Server hardware and RAID configuration practice
![Configure a fixed remote desktop address [intranet penetration, no need for public IP]](/img/17/4e119be86189d80b100eb000254a86.png)





![[226] instructions for Wireshark parameters](/img/47/0d3fd221695920e02b1f690a2a21c1.png)


