当前位置:网站首页>[force deduction 10 days SQL introduction] Day1
[force deduction 10 days SQL introduction] Day1
2022-06-21 19:39:00 【Ly methane】
Li Kou learning plan address :https://leetcode.cn/study-plan/sql/
1. Big country
surface :World
+-------------+---------+
| 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 , That the country is a big country :
The area is at least 300 Square kilometers ( namely ,3000000 km2), Or a population of at least 2500 ten thousand ( namely 25000000)
Write a SQL Query to report Power Name of country 、 Population and area .
answer :
SELECT name, population , area FROM World
WHERE population >= 25000000 OR area >= 3000000
2. Recyclable and low-fat products
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 .
demand
Write SQL sentence , Find product numbers that are both low-fat and recyclable .
Return results No sequence requirements .
answer
SELECT product_id FROM Products
WHERE low_fats= 'Y' AND recyclable = 'Y'
3. Looking for user references
surface 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 |
+------+------+-----------+
demand
Write a query statement , Return a list of customers , The number of the customer's recommender in the list is not 2.
answer
mysql Judge non empty functions
ISNULL(expr) If expr by null Return value 1, Otherwise, the return value is 0
IFNULL(expr1,expr2) If expr1 The value is null return expr2 Value , Otherwise return to expr1 Value
SELECT name FROM customer
WHERE IFNULL(referee_id, 0) != 2
4. Customers who never order
A website contains two tables
Customers surface :
+----+-------+
| Id | Name |
+----+-------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+----+-------+
Orders surface :
+----+------------+
| Id | CustomerId |
+----+------------+
| 1 | 3 |
| 2 | 1 |
+----+------------+
demand
Write a SQL Inquire about , Find all customers who never order anything . namely Orders Not found in CustomerId Of Customers surface
+-----------+
| Customers |
+-----------+
| Henry |
| Max |
+-----------+
answer
SELECT name "Customers" FROM Customers
WHERE Id NOT IN(SELECT CustomerId FROM Orders)
summary
SELECT Name FROM surface WHERE Conditions
ISNULL(expr) -------------expr by null return 1, Otherwise return to 0
IFNULL(expr1, expr2) ------------ expr1 by null return expr2, Otherwise return to expr1
NOT IN -------- The list does not contain
边栏推荐
- ThreadLocal与线程池在使用中可能会出现的两个问题
- 转发提醒 MetaMask小狐狸钱包安全公告 如何应对拓展程序潜在的私钥泄露
- Does the school of Finance and business belong to a securities company? Is it safe to open an account?
- Excel文件加密的两种方式
- SQL操作:WITH表达式及其应用
- R语言使用plyr包的rbind.fill函数纵向合并两个数据列不同的dataframe数据
- What is an SSL certificate and what are the benefits of having an SSL certificate?
- [interval and topic prefix sum] line segment tree (dynamic open point) application problem
- R语言使用glm函数构建泊松回归模型(Poisson Regression)、使用coef函数获取泊松回归模型的系数并分析各个变量的效应
- [high frequency interview questions] difficulty 1/5, popular enumeration simulation questions
猜你喜欢
![Dynamic programming [1] (knapsack problem)](/img/a6/3f60aa162b0597cf91a05bbc2d2b53.png)
Dynamic programming [1] (knapsack problem)

Nebula Graph入驻阿里云计算巢,助力企业打造云上超大规模图数据库

华为又发新品?这几款功能太优秀了
![[pwn基础]Pwntools学习](/img/72/0f80d2f91d772e361b6d23a67e2ca3.png)
[pwn基础]Pwntools学习

Use the uniapp framework to build the zheliban micro application (single sign on, embedded point, aging adaptation, RPC gateway)

Mvcc implementation principle of MySQL

品牌、产品和服务齐发力,东风日产接下来有什么新动作?

jvm造轮子

Insert class collation

How many correct answers can you get to Huawei Hongmeng certification test questions?
随机推荐
Kubernetes 跨 StorageClass 迁移 Persistent Volumes 完全指南
Shang Silicon Valley Shang Silicon Valley | what is Clickhouse table engine memory and merge
Hongmeng version of "Tiktok" is a great experience
全国产加固以太网交换机选择技巧
如何在Chrome浏览器中模拟请求或修改请求的域名
【区间和专题の前缀和】线段树(动态开点)运用题
Post Gartner webinar "nine questions on digital transformation"
使用uniapp框架搭建浙里办微应用(单点登录、埋点、适老化、RPC网关)
Wwdc22 multimedia feature summary
动态规划【一】(背包问题)
2022年6月25日PMP考试通关宝典-5
网管型全国产加固交换机如何创建网络冗余
Does the school of Finance and business belong to a securities company? Is it safe to open an account?
MFC界面库BCGControlBar v33.0 - 桌面警报窗口、网格控件升级
gorm数据库是否需要设置外键
三叶的小伙伴们の经历分享 : 千秋澪(千秋总)
R语言使用epiDisplay包的statStack函数基于因子变量通过分层的方式查看连续变量的统计量(均值、中位数等)以及对应的假设检验
This humble doctor's thesis is very popular: looking back, I feel sorry for countless mountains
How to create network redundancy for network managed national production reinforced switch
How many correct answers can you get to Huawei Hongmeng certification test questions?