当前位置:网站首页>[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
边栏推荐
- 【区间和专题の前缀和】前缀和 + 哈希表 运用题
- Does the school of Finance and business belong to a securities company? Is it safe to open an account?
- C# Mapster 对象映射器学习
- 11 introduction and installation of beautiful soup parsing library
- R语言dist函数计算dataframe数据中两两样本之间的距离并返回样本间距离矩阵,将距离矩阵输入给hclust函数进行层次聚类分析,method参数指定两个组合数据点间的距离计算方式
- Selection skills of national production reinforced Ethernet switch
- CloudCompare&PCL 点云AABB包围盒
- 第298场周赛
- linux-mysql-命令
- 使用uniapp框架搭建浙里办微应用(单点登录、埋点、适老化、RPC网关)
猜你喜欢

Yolov5 trains its own data set to report error records

After Hongmeng, Huawei announced that it would donate to Euler again. What impact is expected to be brought to the industry by the donations of Hongmeng and Euler?

系统集成项目管理工程师(软考中级)怎么备考?

在Qt中设置程序图标的方法介绍

gorm数据库是否需要设置外键

动态规划【二】(线性dp)

Literature analysis CiteSpace 6.1.2 download and installation tutorial

How to simulate a request or modify a requested domain name in Chrome browser

How to temporarily modify samesite=none and secure in Chrome browser

使用uniapp框架搭建浙里办微应用(单点登录、埋点、适老化、RPC网关)
随机推荐
R语言caTools包进行数据划分、randomForest包构建随机森林模型、使用importance函数计算随机森林模型中每个特征的重要度、varImpPlot函数可视化特征的重要度
Qt Creator 7.0常见问题和常见用法
Double pointer 1day8 of daily practice of Li Kou
jvm造轮子
Nebula Graph入驻阿里云计算巢,助力企业打造云上超大规模图数据库
如何使用DevExpress WPF在WinUI中创建第一个MVVM应用?
vivo 容器集群监控系统架构与实践
《Go题库·9》同一个协程里面,对无缓冲channel同时发送和接收数据有什么问题
Enabling developers of shengteng scientific research innovation enabling program Huawei computing provides three dimensional support
文献分析 Citespace 6.1.2 下载及安装教程
R语言glm函数构建二分类logistic回归模型(family参数为binomial)、使用coef函数获取模型系数并解析系数意义
Is it safe to open futures accounts online? Can I open an account without going offline?
Mvcc implementation principle of MySQL
2022 China eye Expo, Shandong Youth eye health exhibition, vision correction and rehabilitation Exhibition
Summary of the 13th week
【面试高频题】难度 1.5/5,经典「前缀和 + 二分」运用题
Easy introduction to naturallanguageprocessing series topic 6 code practice -- spelling correction based on language model
三叶的小伙伴们の经历分享 : 千秋澪(千秋总)
2022年下半年传统产品经理国际资格认证招生简章(NPDP)
mocklog_模拟日志