1821. 寻找今年具有正收入的客户

1821. 寻找今年具有正收入的客户

题目-简单难度

表:Customers

Column Name Type
customer_id int
year int
revenue int
  • (customer_id, year) 是该表的主键(具有唯一值的列的组合)。
    这个表包含客户 ID 和不同年份的客户收入。
    注意,这个收入可能是负数。

编写一个解决方案来报告 2021 年具有 正收入 的客户。

可以以 任意顺序 返回结果表。

结果格式如下示例所示。

示例

示例 1:

Input:

Customers

customer_id year revenue
1 2018 50
1 2021 30
1 2020 70
2 2021 -50
3 2018 10
3 2016 50
4 2021 20

Output:

customer_id
1
4

客户 1 在 2021 年的收入等于 30 。

客户 2 在 2021 年的收入等于 -50 。

客户 3 在 2021 年没有收入。

客户 4 在 2021 年的收入等于 20 。

因此,只有客户 1 和 4 在 2021 年有正收入。

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/summary-ranges
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

1.

时间

561ms

击败 32.84%使用 MySQL 的用户

内存

0.00MB

击败 100.00%使用 MySQL 的用户

sql 复制代码
-- 从cutomers表中选择customer_id列作为返回的结果
SELECT customer_id
FROM customers
-- 该返回结果满足以下限制, customers表中的year列数据为2021, customers表中的revenue数据大于0
WHERE year = 2021 AND revenue > 0
相关推荐
多米Domi0112 小时前
0x3f第33天复习 (16;45-18:00)
数据结构·python·算法·leetcode·链表
Lips6112 小时前
2026.1.16力扣刷题
数据结构·算法·leetcode
今天_也很困4 小时前
LeetCode 热题100-15.三数之和
数据结构·算法·leetcode
千金裘换酒4 小时前
LeetCode 数组经典题刷题
算法·leetcode·职场和发展
香气袭人知骤暖5 小时前
SQL慢查询常见优化步骤
android·数据库·sql
Star Learning Python5 小时前
MySQL日期时间的处理函数
数据库·sql
alphaTao6 小时前
LeetCode 每日一题 2026/1/12-2026/1/18
python·算法·leetcode
sin_hielo6 小时前
leetcode 2943
数据结构·算法·leetcode
程序员-King.8 小时前
day134—快慢指针—环形链表(LeetCode-141)
算法·leetcode·链表·快慢指针
Swift社区8 小时前
LeetCode 376 摆动序列
算法·leetcode·职场和发展