返回介绍

solution / 2000-2099 / 2082.The Number of Rich Customers / README_EN

发布于 2024-06-17 01:03:11 字数 1964 浏览 0 评论 0 收藏 0

2082. The Number of Rich Customers

中文文档

Description

Table: Store

+-------------+------+
| Column Name | Type |
+-------------+------+
| bill_id   | int  |
| customer_id | int  |
| amount    | int  |
+-------------+------+
bill_id is the primary key (column with unique values) for this table.
Each row contains information about the amount of one bill and the customer associated with it.

 

Write a solution to report the number of customers who had at least one bill with an amount strictly greater than 500.

The result format is in the following example.

 

Example 1:

Input: 
Store table:
+---------+-------------+--------+
| bill_id | customer_id | amount |
+---------+-------------+--------+
| 6     | 1       | 549  |
| 8     | 1       | 834  |
| 4     | 2       | 394  |
| 11    | 3       | 657  |
| 13    | 3       | 257  |
+---------+-------------+--------+
Output: 
+------------+
| rich_count |
+------------+
| 2      |
+------------+
Explanation: 
Customer 1 has two bills with amounts strictly greater than 500.
Customer 2 does not have any bills with an amount strictly greater than 500.
Customer 3 has one bill with an amount strictly greater than 500.

Solutions

Solution 1

# Write your MySQL query statement below
SELECT
  COUNT(DISTINCT customer_id) AS rich_count
FROM Store
WHERE amount > 500;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文