当前位置:网站首页>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 .
边栏推荐
- Description of the difference between character varying and character in PostgreSQL database
- [matrix multiplication] [noi 2012] [cogs963] random number generator
- Solve the problem of uni in uni app Request sent a post request without response.
- L2: current situation, prospects and pain points of ZK Rollup
- Demon daddy A1 speech listening initial challenge
- 【矩阵乘】【NOI 2012】【cogs963】随机数生成器
- Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
- 特征生成
- Demon daddy B2 breaks through grammar and completes orthodox oral practice
- Ad domain group policy management
猜你喜欢
![Jerry's test box configuration channel [chapter]](/img/d4/fb67f5ee0fe413c22e4e5cd5037938.png)
Jerry's test box configuration channel [chapter]

NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?

Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade

South China x99 platform chicken blood tutorial

Solve the problem of using uni app mediaerror mediaerror errorcode -5

为什么Win11不能显示秒数?Win11时间不显示秒怎么解决?

Google SEO external chain backlinks research tool recommendation

L2:ZK-Rollup的现状,前景和痛点
MySQL storage expression error

Goal: do not exclude yaml syntax. Try to get started quickly
随机推荐
Validutil, "Rethinking the setting of semi supervised learning on graphs"
JNI primary contact
Codeforces round 296 (Div. 2) A. playing with paper[easy to understand]
Can I open a stock account directly online now? Is it safe?
为什么Win11不能显示秒数?Win11时间不显示秒怎么解决?
NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?
Contour layout of margin
Jerry's power on automatic pairing [chapter]
Use camunda to do workflow design and reject operations
Ad domain group policy management
浅解ARC中的 __bridge、__bridge_retained和__bridge_transfer
How much does it cost to develop a small program mall?
Reinforcement learning - learning notes 8 | Q-learning
[200 opencv routines] 223 Polygon fitting for feature extraction (cv.approxpolydp)
私募基金在中国合法吗?安全吗?
FatMouse' Trade(杭电1009)
UVA 11080 – place the guards
Goal: do not exclude yaml syntax. Try to get started quickly
Deadlock conditions and preventive treatment [easy to understand]
Meta force force meta universe system development fossage model