当前位置:网站首页>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 .
边栏推荐
- Jerry's configuration of TWS cross pairing [article]
- 解决uni-app中uni.request发送POST请求没有反应。
- Focusing on safety in 1995, Volvo will focus on safety in the field of intelligent driving and electrification in the future
- NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
- Demon daddy A3 stage near normal speed speech flow initial contact
- Backup tidb cluster to persistent volume
- Default constraint and zero fill constraint of MySQL constraint
- The maximum number of meetings you can attend [greedy + priority queue]
- object-c编程tips-timer「建议收藏」
- 648. Word replacement
猜你喜欢
How does win11 time display the day of the week? How does win11 display the day of the week today?
The new version of onespin 360 DV has been released, refreshing the experience of FPGA formal verification function
Jerry's initiation of ear pairing, reconnection, and opening of discoverable and connectable cyclic functions [chapter]
Jenkins user rights management
ISO 26262 - considerations other than requirements based testing
The little money made by the program ape is a P!
Use camunda to do workflow design and reject operations
QT compile IOT management platform 39 alarm linkage
2022 how to evaluate and select low code development platforms?
EasyCVR配置中心录像计划页面调整分辨率时的显示优化
随机推荐
[UVALive 6663 Count the Regions] (dfs + 离散化)[通俗易懂]
Is it safe to open an account of BOC shares in kainiu in 2022?
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
Tupu digital twin coal mining system to create "hard power" of coal mining
Prometheus remote_ write InfluxDB,unable to parse authentication credentials,authorization failed
嵌入式开发:如何为项目选择合适的RTOS?
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?
An in-depth understanding of fp/fn/precision/recall
Jetty: configure connector [easy to understand]
Code of "digital image processing principle and Practice (matlab version)" part2[easy to understand]
Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
648. Word replacement
L2: current situation, prospects and pain points of ZK Rollup
Can Huatai Securities achieve Commission in case of any accident? Is it safe to open an account
Jerry's fast pairing does not support canceling pairing [article]
Object-C programming tips timer "suggestions collection"
Jerry's power on automatic pairing [chapter]
Default constraint and zero fill constraint of MySQL constraint
Win11时间怎么显示星期几?Win11怎么显示今天周几?
Jerry's initiation of ear pairing, reconnection, and opening of discoverable and connectable cyclic functions [chapter]