题目分析
我们需要从 user_profile
表中选择 device_id
和 university
列,并且只返回 university
为“北京大学”的记录。
解题思路
- 选择列:我们只需要提取
device_id
和university
列。 - 过滤条件:使用
WHERE
子句来筛选university
为“北京大学”的记录。
SQL 查询
以下是实现上述思路的 SQL 查询:
SELECT device_id, university
FROM user_profile
WHERE university = '北京大学';
解释
SELECT device_id, university
: 选择device_id
和university
列。FROM user_profile
: 从user_profile
表中获取数据。WHERE university = '北京大学'
: 只返回university
为“北京大学”的记录。