当前位置:网站首页>Leetcode SQL first day
Leetcode SQL first day
2022-07-07 21:45:00 【liyatjj】
List of articles
1. Big country
World surface :
±------------±--------+
| Column Name | Type |
±------------±--------+
| name | varchar |
| continent | varchar |
| area | int |
| population | int |
| gdp | int |
±------------±--------+
name It's the primary key of this table .
Each row of this table provides : Country name 、 Continent 、 area 、 Population and GDP value .
If a country meets one of the following two conditions , The country is considered to be Power :
The area is at least 300 10,000 square kilometers ( namely ,3000000 km2), perhaps
The population is at least 2500 ten thousand ( namely 25000000)
Write a SQL Query to report Power Name of country 、 Population and area .
select name,population,area
from World
where area >=3000000 or population >=25000000
2. Recyclable and low-fat products
SQL framework
surface :Products
±------------±--------+
| Column Name | Type |
±------------±--------+
| product_id | int |
| low_fats | enum |
| recyclable | enum |
±------------±--------+
product_id It's the primary key of this table .
low_fats Is enumeration type , The values are the following two (‘Y’, ‘N’), among ‘Y’ Indicates that the product is a low-fat product ,‘N’ It means it's not a low-fat product .
recyclable Is enumeration type , The values are the following two (‘Y’, ‘N’), among ‘Y’ Indicates that the product is recyclable , and ‘N’ Indicates non recyclable .
Write SQL sentence , Find product numbers that are both low-fat and recyclable .
select product_id
from Products
where low_fats='Y' && recyclable='Y'
3. Looking for user references
SQL framework
Given table customer , It contains all the customer information and their references .
±-----±-----±----------+
| id | name | referee_id|
±-----±-----±----------+
| 1 | Will | NULL |
| 2 | Jane | NULL |
| 3 | Alex | 2 |
| 4 | Bill | NULL |
| 5 | Zack | 1 |
| 6 | Mark | 2 |
±-----±-----±----------+
Write a query statement , Return a list of customers , The number of the customer's recommender in the list is No 2.
source :LeetCode
SELECT name
FROM customer
WHERE referee_id != 2 or referee_id is NULL
This needs to pay attention to the situation when it is empty .
4. Customers who never order
SQL framework
A website contains two tables ,Customers Table and Orders surface . Write a SQL Inquire about , Find all customers who never order anything .
Customers surface :
±—±------+
| Id | Name |
±—±------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
±—±------+
Orders surface :
±—±-----------+
| Id | CustomerId |
±—±-----------+
| 1 | 3 |
| 2 | 1 |
±—±-----------+
source :LeetCode
SELECT Name Customers
FROM Customers
WHERE Id not in
(
SELECT CustomerId FROM Orders
);
This requires attention to the relationship between the two tables , yes Customers Of Id and Orders Of CustomerId compare .
边栏推荐
- Codeforces 474 F. Ant colony
- Talk about relational database and serverless
- Word inversion implements "suggestions collection"
- FatMouse' Trade(杭电1009)
- HOJ 2245 浮游三角胞(数学啊 )
- Codeforces 474 F. Ant colony
- 201215-03-19 - cocos2dx memory management - specific explanation "recommended collection"
- Ant destination multiple selection
- Devil daddy B1 hearing the last barrier, break through with all his strength
- 大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
猜你喜欢

Dry goods sharing | devaxpress v22.1 original help document download collection
![[200 opencv routines] 223 Polygon fitting for feature extraction (cv.approxpolydp)](/img/1e/055df228853d9b464fc4bcbde0a7ee.png)
[200 opencv routines] 223 Polygon fitting for feature extraction (cv.approxpolydp)

648. Word replacement

Ad domain group policy management

The little money made by the program ape is a P!

EasyCVR配置中心录像计划页面调整分辨率时的显示优化

Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘

建立自己的网站(18)

L'enregistreur de disque dur NVR est connecté à easycvr par le Protocole GB 28181. Quelle est la raison pour laquelle l'information sur le canal de l'appareil n'est pas affichée?

How does win11 unblock the keyboard? Method of unlocking keyboard in win11
随机推荐
Demon daddy A1 speech listening initial challenge
Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)
Use br to recover backup data on azure blob storage
Word inversion implements "suggestions collection"
Codeforces round 275 (Div. 2) C – diverse permutation (construction) [easy to understand]
Dry goods sharing | devaxpress v22.1 original help document download collection
[开源] .Net ORM 访问 Firebird 数据库
OpenGL super classic learning notes (1) the first triangle "suggestions collection"
Usage of MySQL subquery keywords (exists)
Datatable data conversion to entity
QT compile IOT management platform 39 alarm linkage
【矩阵乘】【NOI 2012】【cogs963】随机数生成器
Hoj 2245 planktonic triangle cell (Mathematics)
Static test tool
The new version of onespin 360 DV has been released, refreshing the experience of FPGA formal verification function
Reptile combat (VII): pictures of the king of reptiles' heroes
Win11U盘不显示怎么办?Win11插U盘没反应的解决方法
What is the reason for the abnormal flow consumption of 4G devices accessing the easygbs platform?
POJ 3140 contents division "suggestions collection"
Problems encountered in installing mysql8 for Ubuntu and the detailed installation process