列表

详情


584. 寻找用户推荐人

给定表 customer ,里面保存了所有客户信息和他们的推荐人。

+------+------+-----------+
| id   | name | referee_id|
+------+------+-----------+
|    1 | Will |      NULL |
|    2 | Jane |      NULL |
|    3 | Alex |         2 |
|    4 | Bill |      NULL |
|    5 | Zack |         1 |
|    6 | Mark |         2 |
+------+------+-----------+

写一个查询语句,返回一个客户列表,列表中客户的推荐人的编号都 不是 2。

对于上面的示例数据,结果为:

+------+
| name |
+------+
| Will |
| Jane |
| Bill |
| Zack |
+------+

原站题解

去查看

上次编辑到这里,代码来自缓存 点击恢复默认模板
# Write your MySQL query statement below

pythondata 解法, 执行用时: 338 ms, 内存消耗: 65.4 MB, 提交时间: 2024-05-27 11:18:57

import pandas as pd

def find_customer_referee1(customer: pd.DataFrame) -> pd.DataFrame:
    return pd.DataFrame(customer[customer['referee_id'].fillna(0) != 2]['name'])
    
    
# 两组条件结合
def find_customer_referee(customer: pd.DataFrame) -> pd.DataFrame:
    return customer[((customer['referee_id']!=2) | (customer['referee_id'].isnull()))][['name']]

mysql 解法, 执行用时: 488 ms, 内存消耗: 0 B, 提交时间: 2022-05-29 13:49:06

# Write your MySQL query statement below
select name from customer where referee_id<>2 or referee_id is null;

mysql 解法, 执行用时: 478 ms, 内存消耗: 0 B, 提交时间: 2022-05-26 17:05:18

# Write your MySQL query statement below
select name from customer where referee_id<>2 or referee_id is null;

上一题