当前位置:网站首页>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 .
边栏推荐
- How does win11 time display the day of the week? How does win11 display the day of the week today?
- Feature generation
- Ten thousand word summary data storage, three knowledge points
- [uvalive 6663 count the regions] (DFS + discretization) [easy to understand]
- Win11时间怎么显示星期几?Win11怎么显示今天周几?
- 现在网上开户安全么?想知道我现在在南宁,到哪里开户比较好?
- Use br to recover backup data on azure blob storage
- 你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......
- FatMouse' Trade(杭电1009)
- Codeforces round 275 (Div. 2) C – diverse permutation (construction) [easy to understand]
猜你喜欢

EasyCVR配置中心录像计划页面调整分辨率时的显示优化
![Restapi version control strategy [eolink translation]](/img/65/decbc158f467ab8c8923c5947af535.png)
Restapi version control strategy [eolink translation]

Problems encountered in installing mysql8 for Ubuntu and the detailed installation process
![[C language] advanced pointer --- do you really understand pointer?](/img/ee/79c0646d4f1bfda9543345b9da0f25.png)
[C language] advanced pointer --- do you really understand pointer?
![[开源] .Net ORM 访问 Firebird 数据库](/img/a2/4eff4f0af53bf3b9839a73019a212f.png)
[开源] .Net ORM 访问 Firebird 数据库

Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?

An in-depth understanding of fp/fn/precision/recall

L2: current situation, prospects and pain points of ZK Rollup

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?
![Jerry's manual matching method [chapter]](/img/92/74281c29565581ecb761230fbfd0f3.png)
Jerry's manual matching method [chapter]
随机推荐
Insufficient permissions
Jerry's fast pairing does not support canceling pairing [article]
Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
Magic weapon - sensitive file discovery tool
648. Word replacement
Le capital - investissement est - il légal en Chine? C'est sûr?
Deadlock conditions and preventive treatment [easy to understand]
What is the reason for the abnormal flow consumption of 4G devices accessing the easygbs platform?
What are the official stock trading apps in the country? Is it safe to use
L2: current situation, prospects and pain points of ZK Rollup
Unity3d 4.3.4f1 execution project
Using enumeration to realize English to braille
Demon daddy guide post - simple version
Take the intersection of two sets
Static test tool
Codeforces Round #275 (Div. 2) C – Diverse Permutation (构造)[通俗易懂]
Virtual machine network configuration in VMWare
Lex & yacc of Pisa proxy SQL parsing
OpenGL super classic learning notes (1) the first triangle "suggestions collection"
开户还得用身份证银行卡安全吗,我是小白不懂