当前位置:网站首页>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 .
边栏推荐
- 【JDBC Part 1】概述、获取连接、CRUD
- Goal: do not exclude yaml syntax. Try to get started quickly
- Datatable data conversion to entity
- gridView自己定义做时间排版「建议收藏」
- A brief understanding of the in arc__ bridge、__ bridge_ Retained and__ bridge_ transfer
- Nine degree 1201 - traversal of binary sort number - binary sort tree "suggestions collection"
- Reinforcement learning - learning notes 8 | Q-learning
- Use br to back up tidb cluster data to azure blob storage
- The maximum number of meetings you can attend [greedy + priority queue]
- Demon daddy B3 read extensively in a small amount, and completed 20000 vocabulary+
猜你喜欢
Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade
Virtual machine network configuration in VMWare
Win11U盘不显示怎么办?Win11插U盘没反应的解决方法
Use camunda to do workflow design and reject operations
Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
Automatic classification of defective photovoltaic module cells in electronic images
建立自己的网站(18)
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
The new version of onespin 360 DV has been released, refreshing the experience of FPGA formal verification function
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?
随机推荐
Qt编写物联网管理平台39-报警联动
私募基金在中國合法嗎?安全嗎?
Solve the problem of using uni app mediaerror mediaerror errorcode -5
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
The difference between NPM uninstall and RM direct deletion
201215-03-19 - cocos2dx memory management - specific explanation "recommended collection"
How polardb-x does distributed database hotspot analysis
The maximum number of meetings you can attend [greedy + priority queue]
South China x99 platform chicken blood tutorial
Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade
[开源] .Net ORM 访问 Firebird 数据库
Song list 11111
Embedded development: how to choose the right RTOS for the project?
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
特征生成
Goal: do not exclude yaml syntax. Try to get started quickly
Reinforcement learning - learning notes 8 | Q-learning
HOJ 2245 浮游三角胞(数学啊 )
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
Unity3d 4.3.4f1执行项目