当前位置:网站首页>SQL realizes 10 common functions of Excel, with original interview questions attached
SQL realizes 10 common functions of Excel, with original interview questions attached
2022-07-25 18:46:00 【Python data mining】
SQL Is it difficult? ? Tell the truth , Write well , It's hard. . But through SQL Written examination , It is not difficult to . I believe everyone has used Excel, use SQL Realization excel Use common operations to learn , I think it will be more specific . I have just joined the data post myself , This article is also for yourself to consolidate SQL.
SQL Interview questions 、 Technical communication , At the end of the article, ask me to get
Data is the sales data found online , Name it sale, Long like this :

01. Correlation formula :Vlookup
vlookup yes excel Almost the most commonly used formula , It is generally used for the association query of two tables . So I first create a new table : Copy sale Table and screen out the areas only in Guangzhou , Name it sale_guang.
create table sale_guang
SELECT * from sale where city=" Guangzhou ";
demand : Associate the two tables according to the order detail number , also sale_guang There are only two columns: order detail number and profit
SELECT * from sale a
inner JOIN
(SELECT ordernum,profit from sale_guang) b
on a.ordernum=b.ordernum
02. Compare the differences between the two columns
demand : contrast sale The order detail number and sale_guang Difference of order detail number ;
SELECT * from sale a
WHERE a.ordernum not in
(SELECT b.ordernum from sale_guang b);
03. Remove duplicate values
demand : Remove duplicate values of operator codes
SELECT * FROM sale
where salesnum not in
(SELECT salesnum from sale
GROUP BY salesman
HAVING COUNT(salesnum)>1)
04. Missing value processing
demand : use 0 Fill in the missing value or delete the row with the missing value of the region name .
-- use 0 fill :
update sale set city = 0 where city = NULL
-- Delete rows with missing values :
delete from sale where city = NULL;
05. Multi criteria screening
demand : Want to know salesman Zhang Ai , The order amount of goods sold in Beijing is greater than or equal to 6000 Information about .
SELECT * from sale
where salesman = " Zhang Ai "
and city = " Beijing "
and orderaccount >=6000;
06. Fuzzy filtering data
demand : The filtered inventory name contains " samsung " Or contain " SONY " Information about .
SELECT * from sale
where inventoryname like "% samsung %"
or Inventory name like "% SONY %";
07. Subtotal
demand : The total profit of each salesman in Beijing .
SELECT city,sum(`profit`)
from sale
WHERE city = " Beijing "
GROUP BY `city`;
08. Conditional calculation
demand : Inventory name includes “ Three stars ” And the tax is higher than 1000 There are several orders for ? What is the total profit and average profit of these orders ?
-- How many ?
SELECT COUNT(*) from sale
where inventoryname like "% samsung %"
and `tax` > 1000 ;
-- What is the total profit and average profit of these orders ?
SELECT `ordernum`,SUM(profit),AVG(`profit`)
from sale
where inventoryname like "% samsung %"
and `tax` > 1000
GROUP BY `ordernum`;
09. Delete spaces between data
demand : Delete the space around the inventory name .
SELECT trim(inventoryname) from sale;
10. Merge and sort
demand : Calculate the cost of each order number and sort it from high to low ( cost = Amount excluding tax - profits )
SELECT city,ordernum,
(Nontaxamount - profit) as cost
from sale
order by cost DESC;
summary : Structured query language (Structured Query Language) abbreviation SQL, Sure enough, it has the same name , It's easy to query , But I want to do data processing , Can feel more than Python and excel Hard work ( Or maybe I haven't learned well orz).
SQL The original question of the written examination
Post some I met during the interview SQL Written examination questions :
A data service company :

Student surface

Score surface
(1) Inquire about Student All the records in the table Sname、Ssex and Class Column .
select sname,ssex,class from student;
(2) Inquire about Score The score in the table is 60 To 80 All records between .
select * from score between 60 and 80;
(3) Inquire about 95033 Class and 95031 Class average .
select class,avg(degree) from Score a
join student b
on a.sno = b.sno
GROUP BY CLASS;
In short, it is relatively simple SQL Written examination questions , It was finished very soon . Actually, this is not the original topic , However, I have the impression that these knowledge points are investigated , And it's quite simple .
From a mobile game company SQL Pen test ( The original title is )

(1) Create a table Student Write down the sentence , surface Student By student number Sno, full name Sname, Gender Ssex, Age Sage, Department Sdept Five attributes make up , The student number attribute cannot be empty , And its value is unique .
create table Student_new
(sno varchar(20) PRIMARY KEY,
sname varchar(10),ssex char(2),
sage int,sdept varchar(25));
(2) stay student Query in table Sdept yes “ Computer ” And press SNO Column sorting .
select * from student
where sdept = " Computer "
order by sno ;
(3) Query in the above three tables Ccredit by 5 also Grade Greater than 60 Student's student number 、 Name and gender .
select a.sno,a.sname,a.ssex from student a
join (Course b ,SC c)
on a.sno=c.sno and b.cno =c.cno
where Ccredit = 5 and Grade > 60;
Some Internet finance companies SQL Pen test ( The original title is )
Full version , Come to me for

(1) surface A And table B Intersection :
SELECT a.cus_id from ` surface a` as a
INNER JOIN ` surface b` as b
on a.cus_id=b.cus_id;
(2) surface A And table B Union :
SELECT * from ` surface a`
UNION
SELECT * from ` surface b`;
(3) surface A And table B Symmetry difference of :
SELECT * from ` surface a`
where cus_id not in (SELECT * from ` surface b`)
UNION
SELECT * from ` surface b`
where cus_id not in (SELECT * from ` surface a`);
(4) surface A Exists in but table B Does not exist in the :
SELECT * from ` surface a`
WHERE cus_id not in (SELECT cus_id from ` surface b`);
Contact information
At present, a technical exchange group has been opened , Group friends have exceeded 3000 people , The best way to add notes is : source + Interest direction , Easy to find like-minded friends , Data acquisition can also be added
The way 1、 Add microsignals :dkl88191, remarks : come from CSDN
The way 2、 WeChat search official account :Python Learning and data mining , The background to reply : Add group 
边栏推荐
- 【开源工程】STM32C8T6+ADC信号采集+OLED波形显示
- Register carefully! The number of applicants for these double non-governmental institutions exceeded 10000!
- Dachang cloud business adjustment, a new round of war turn
- 微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
- Nc68 jumping steps
- Interpretation of "cross chain interconnection smart contract"
- Care for front-line epidemic prevention workers, Haocheng JIAYE and Gaomidian sub district office jointly build the great wall of public welfare
- Common file operations
- 给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
- #yyds干货盘点# 面试必刷TOP101:反转链表
猜你喜欢

单臂路由实验演示(Huawei路由器设备配置)

The understanding of domain adaptation in transfer learning and the introduction of three technologies

There was an error while marking a file for deletion

关爱一线防疫工作者,浩城嘉业携手高米店街道办事处共筑公益长城

With a market value of 30billion yuan, the largest IPO in Europe in the past decade was re launched on the New York Stock Exchange

VC/PE正跑向青岛

Twitter acquired a public opinion war, which was turned into a child quarrel by musk

Communication between processes (pipeline communication)

There are several browser cores. How to upgrade if the browser version is too low

【帮助中心】为您的客户提供自助服务的核心选项
随机推荐
Communication between processes (pipeline communication)
阿里云技术专家郝晨栋:云上可观测能力——问题的发现与定位实践
F5:企业数字化转型所需六大能力
终极套娃 2.0 | 云原生交付的封装
「跨链互连智能合约」解读
[translation] LFX 2022 spring tutor qualification opening - apply for CNCF project before February 13!
如何创建一个有效的帮助文档?
项目:串口接收—ram存储—TFT显示(完整设计)
接口自动化测试平台FasterRunner系列(三)- 操作示例
Interpretation of "cross chain interconnection smart contract"
Project: serial port receiving RAM storage TFT display (complete design)
[QNX hypervisor 2.2 user manual]9.4 dryrun
15. Simple salary management system design
ServletConfig class and ServletContext class
ES6 implements the observer mode through proxy and reflection
阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程?
Osmosis extends its cross chain footprint to poca through integration with axelar and moonbeam
「Wdsr-3」蓬莱药局 题解
There are several browser cores. How to upgrade if the browser version is too low
Nc68 jumping steps