当前位置:网站首页>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 
边栏推荐
猜你喜欢

微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告

市值300亿,欧洲十年来最大IPO再冲纽交所

Powell's function of Ceres

With a financing of 200million yuan, the former online bookstore is now closed nationwide, with only 3 stores left in 60 stores

TypeError: Unrecognized value type: <class ‘str‘> ParserError: Unknown string format

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

浏览器内核有几种,浏览器版本过低怎么升级

这届年轻人,为“丑东西”有多上头?

Northeast people know sexiness best

Automatic machine learning library: Tpot の learning notes
随机推荐
VC/PE正跑向青岛
如何创建一个有效的帮助文档?
3de 回复
接口自动化测试平台FasterRunner系列(一)- 简介、安装部署、启动服务、访问地址、配置补充
15. Simple salary management system design
【小程序开发】页面导航详解
rust多线程安全计数
Osmosis通过与Axelar和Moonbeam的集成将跨链足迹扩展至波卡
Esp32 S3 vscode+idf setup
Osmosis extends its cross chain footprint to poca through integration with axelar and moonbeam
软件测试进阶篇—测试分类
With a financing of 200million yuan, the former online bookstore is now closed nationwide, with only 3 stores left in 60 stores
单臂路由实验演示(Huawei路由器设备配置)
A brief history from object detection to image segmentation
【帮助中心】为您的客户提供自助服务的核心选项
Process communication (Systemv communication mode: shared memory, message queue, semaphore)
Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge
给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
Project: serial port receiving RAM storage TFT display (complete design)
[noi2015] package manager