当前位置:网站首页>Niuke question brushing record -- MySQL
Niuke question brushing record -- MySQL
2022-07-23 11:21:00 【Cheryl_ Xu】
List of articles
- One 、 Simple class
- 1、SQL15 lookup employees surface emp_no And last_name Employee information ---- Odd number 、 For a certain value
- 2、SQL17 Get the salary of the employee with the second highest salary emp_no And the corresponding salary salary----limit 1,1
- 3、SQL32 take employees Table for all employees last_name and first_name Spliced together as Name----concat
- 4、SQL34 Bulk insert data ----insert into
- 5、SQL72 Test scores ( One )----round(x,y)
- 6、SQL77 Course order analysis of Niuke ( One )---- The variable value should be quoted in condition judgment
- 7、SQL45 take titles_test Change the table name to titles_2017----ALTER
- 8、SQL84 Internship square delivery resume analysis ( One )----having And where The difference between ,>= <=
- 9、SQL64 Find everyone's task -- There is 2 Table connection ,on The corresponding is different
- 10、SQL43 Will all to_date by 9999-01-01 Update all of to NULL--update set
- 11、SQL42 Delete emp_no Duplicate records , Keep only the smallest id Corresponding records --delete from
- 12、SQL44 take id=5 as well as emp_no=10001 Replace the row data with id=5 as well as emp_no=10005--replace
- Two 、 Medium class
- 3、 ... and 、 Basic knowledge records
One 、 Simple class
1、SQL15 lookup employees surface emp_no And last_name Employee information ---- Odd number 、 For a certain value
# The job number is odd , Last name is not Mary
where emp_no%2=1 and last_name not like 'Mary'
2、SQL17 Get the salary of the employee with the second highest salary emp_no And the corresponding salary salary----limit 1,1
# limit 1,1: Choose second , Take only 1 individual
select emp_no,salary
from salaries
where salary = (select distinct salary from salaries order by salary desc limit 1,1)
3、SQL32 take employees Table for all employees last_name and first_name Spliced together as Name----concat
concat function , take 2 Values are spliced together
select concat(last_name,' ',first_name) as Name
from employees
4、SQL34 Bulk insert data ----insert into
insert into XX surface values (),()
Be careful :values, Use commas between data ,SQL Sentence use ; end .
insert into actor
values(1,'PENELOPE','GUINESS',' 2006-02-15 12:34:33'),(2,'NICK','WAHLBERG','2006-02-15 12:34:33')
5、SQL72 Test scores ( One )----round(x,y)
round(x,y) Aggregate functions , For data x rounding , And keep y Decimal place
select job,round(avg(score),3) as avg
from grade
group by job
order by avg desc
6、SQL77 Course order analysis of Niuke ( One )---- The variable value should be quoted in condition judgment
select *
from order_info
where date>'2025-10-15' and product_name in ('C++','Java','Python') and status='completed'
7、SQL45 take titles_test Change the table name to titles_2017----ALTER
Use ALTER Modify the table name
alter table titles_test rename to titles_2017
8、SQL84 Internship square delivery resume analysis ( One )----having And where The difference between ,>= <=
select job,sum(num) as cnt
from resume_info
# You can't use having, It can be used where. You can't use a comparative formula , It can be used and Connect 2 Bar formula .
# When select select date, It can be used having.having It doesn't have to be with group Use it with .
where date>='2025-01-01' and date<='2025-12-30'
group by job
order by cnt desc
9、SQL64 Find everyone's task – There is 2 Table connection ,on The corresponding is different

select person.id,person.name,task.content
from person left join task
on person.id=task.person_id
10、SQL43 Will all to_date by 9999-01-01 Update all of to NULL–update set
Update data :update XX surface set xxx=‘’, yyy=‘’
Be careful :null Is a special character , You don't need quotes
update titles_test set to_date=null,from_date='2001-01-01'
where to_date='9999-01-01'
11、SQL42 Delete emp_no Duplicate records , Keep only the smallest id Corresponding records –delete from
A new generation of a The table is only id Table of , The reason for renaming , Because you cannot search and delete at the same time
DELETE FROM titles_test
WHERE id NOT IN(
SELECT * FROM(
SELECT MIN(id)
FROM titles_test
GROUP BY emp_no)a);
12、SQL44 take id=5 as well as emp_no=10001 Replace the row data with id=5 as well as emp_no=10005–replace
xxx=replace(xxx, The value of the original , New value )
update titles_test
set emp_no=replace(emp_no,'10001','10005')
where id='5'
Two 、 Medium class
1、SQL36 Create a actor_name surface
The key to solving the problem is :
Use actor Table data , So available (select …) perhaps as select
Please create a actor_name surface , And will actor All in the table first_name as well as last_name Import this table .
actor_name The table structure is as follows , The title will be queried at the end actor_name Compare the results with the data in the table :
create table actor_name as select first_name,last_name from actor;
# perhaps
create table actor_name (select first_name,last_name from actor);
2、SQL29 Use join Search to find movies without classification id And the name
# Query value is empty , Use is null, Instead of =null
where film_category.category_id is null
where film_category.category_id = null
3、SQL22 Count the salary records of each department
Multi-table query , Be careful group by Which parameter of
It's easy to get wrong :① Should be count, instead of sum;②group by Should be dept_no, instead of salary
select departments.dept_no,departments.dept_name,count(salaries.salary) as sum
from departments left join dept_emp on departments.dept_no=dept_emp.dept_no left join salaries on dept_emp.emp_no=salaries.emp_no
group by departments.dept_no
4、SQL19 Find all employees last_name and first_name And corresponding dept_name
Usually use left connection
select employees.last_name,employees.first_name,departments.dept_name
from employees left join dept_emp on employees.emp_no=dept_emp.emp_no left join departments on dept_emp.dept_no=departments.dept_no
3、 ... and 、 Basic knowledge records
1、 Delete table -DROP
drop table if exists XX surface
2、 Field
smallint、datatime
3、ALTER
ALTER TABLE Table name ADD Name / Indexes / Primary key / Foreign keys, etc ;
ALTER TABLE Table name DROP Name / Indexes / Primary key / Foreign keys, etc ;
ALTER TABLE Table name ALTER Only used to change the default value of a column ;
ALTER TABLE Table name RENAME Name / Index name TO New column names / The new index ;
ALTER TABLE Table name RENAME TO/AS The new name of the table ;
ALTER TABLE Table name MODIFY The definition of the column, but does not change the column name ;
ALTER TABLE Table name CHANGE Column names and definitions can be changed .
边栏推荐
- 解决手动查询Oracle数据库时间格式不正确的问题(DATE类型)
- [部署]presto-server-0.261.tar.gz的集群部署和启动
- 【无标题】
- Understanding of closures of JS
- Dictionary creation and copying
- js的继承方式
- The super simple face recognition API can realize face recognition in just a few lines of code
- Send SMS verification code synchronously
- Cell sends SMS asynchronously
- 3. Threads in flask
猜你喜欢
![[pytho-flask筆記5]藍圖簡單使用](/img/0a/00b259f42e2fa83d4871263cc5f184.png)
[pytho-flask筆記5]藍圖簡單使用

systemctl-service服务添加环境变量及模板

pyspark学习笔记

Pycharm occupies C disk

Web server failed to start. Port 8080 was already in use.

PyGame realizes the airplane war game

Pywinauto+某应用程序(学习至第9讲)--受阻

Spark common interview questions sorting

Cell sends SMS asynchronously
![[监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表](/img/34/b7a05bff05e1d3a1daef4fb2b98a92.png)
[监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表
随机推荐
When using cache in sprintboot, the data cannot be loaded
Analysis of flask source code (I) request entry
混入视图基类
TypeScript 高级类型
slice()和splice()区别
大厂面试机器学习算法(6)时间序列分析
Understanding of closures of JS
Five methods to prevent over fitting of neural network
高阶函数的应用:手写Promise源码(四)
Error when PLSQL creates Oracle Database: when using database control to configure the database, it is required to configure the listener in the current Oracle home directory. You must run netca to co
Pyspark learning notes
大厂面试机器学习算法(0):特征工程 | 数据预处理
Use of views
JWT header for coding process
D2DEngine食用教程(2)———绘制图像
First blog
【6.28】
Request data acquisition and response
[untitled]
【无标题】