- 0
- 0
- 约5.49千字
- 约 15页
- 2026-01-31 发布于福建
- 举报
第PAGE页共NUMPAGES页
2026年腾讯数据工程师面试题集
一、编程能力题(共5题,每题10分)
1.SQL编程题(10分)
题目:
假设有一个订单表`orders`,字段包括`order_id`(订单ID)、`user_id`(用户ID)、`order_date`(订单日期)、`total_amount`(订单金额)。另有一个用户表`users`,字段包括`user_id`(用户ID)、`register_date`(注册日期)、`city`(城市)。
请编写SQL查询,统计每个城市在2025年注册的用户中,订单金额总和最高的前3名用户及其订单金额。
答案与解析:
sql
WITHRegisteredUsersAS(
SELECTuser_id,city
FROMusers
WHEREregister_dateBETWEEN2025-01-01AND2025-12-31
),AggregatedOrdersAS(
SELECT
o.user_id,
SUM(o.total_amount)AStotal_spent
FROMorderso
JOINRegisteredUsersruONo.user_id=ru.user_id
WHEREo.order_dateBETWEEN2025-01-01AND2025-12-31
GROUPBYo.user_id,ru.city
)
SELECT
ao.city,
ao.user_id,
ao.total_spent
FROMAggregatedOrdersao
ORDERBYao.total_spentDESC
LIMIT3;
解析:
1.首先通过`WITH`子句筛选出2025年注册的用户(`RegisteredUsers`);
2.然后根据`user_id`关联订单表,并按城市和用户分组统计订单金额总和(`AggregatedOrders`);
3.最后按订单金额降序排序,取前3名结果。
2.Python编程题(10分)
题目:
给定一个包含多个嵌套字典的列表,例如:
python
data=[
{name:Alice,scores:{math:90,english:85}},
{name:Bob,scores:{math:78,english:92}},
{name:Charlie,scores:{math:85,english:88}}
]
请编写Python代码,计算每个用户的平均分数,并输出平均分数最高的用户及其平均分。
答案与解析:
python
fromtypingimportList,Dict
deffind_top_student(data:List[Dict[str,Dict[str,int]]])-str:
total_scores={}
forstudentindata:
name=student[name]
scores=student[scores]
avg_score=sum(scores.values())/len(scores)
total_scores[name]=avg_score
top_student=max(total_scores,key=total_scores.get)
returntop_student,total_scores[top_student]
示例调用
data=[
{name:Alice,scores:{math:90,english:85}},
{name:Bob,scores:{math:78,english:92}},
{name:Charlie,scores:{math:85,english:88}}
]
top_student,avg_score=find_top_student(data)
print(fTopstudent:{top_student},Averagescore:{avg_score})
解析:
1.遍历列表,计算每个用户的平均分数并存储在`total_scores`字典中;
2.使用`max`函数按平均分数排序,找出最高分用户;
3.返回结果。
3.Pandas编程题(10分)
题目:
假设有一个DataFrame`df`,包含以下列:`date`(日期)、`product_id`(产品ID)、`sales`(销售额)。请编写Pandas代码,按月统计每个产品的总销售额,并按销售额降序排列。
答案与解析:
python
i
原创力文档

文档评论(0)