LeetCode MySQL 1045. 买下所有产品的客户
生活随笔
收集整理的這篇文章主要介紹了
LeetCode MySQL 1045. 买下所有产品的客户
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 題目
- 2. 解題
1. 題目
Customer 表:
+-------------+---------+ | Column Name | Type | +-------------+---------+ | customer_id | int | | product_key | int | +-------------+---------+ product_key 是 Product 表的外鍵。Product 表:
+-------------+---------+ | Column Name | Type | +-------------+---------+ | product_key | int | +-------------+---------+ product_key 是這張表的主鍵。寫一條 SQL 查詢語句,從 Customer 表中查詢購買了 Product 表中所有產品的客戶的 id。
示例:
Customer 表: +-------------+-------------+ | customer_id | product_key | +-------------+-------------+ | 1 | 5 | | 2 | 6 | | 3 | 5 | | 3 | 6 | | 1 | 6 | +-------------+-------------+Product 表: +-------------+ | product_key | +-------------+ | 5 | | 6 | +-------------+Result 表: +-------------+ | customer_id | +-------------+ | 1 | | 3 | +-------------+ 購買了所有產品(5 和 6)的客戶的 id 是 1 和 3 。來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/customers-who-bought-all-products
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
2. 解題
# Write your MySQL query statement below select c.customer_id from Customer c group by c.customer_id having (select distinct count(*) from Product) = count(distinct c.product_key)457 ms
我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的LeetCode MySQL 1045. 买下所有产品的客户的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 713. 乘积小于K的
- 下一篇: LeetCode 1245. 树的直径(