目录
1. 基础查询
1.1 SQL1 查询多列
题目:现在运营同学想要用户的设备id对应的年龄、性别和学校的数据,请你取出相应数据
示例:user_profile
根据示例,你的查询应返回以下结果
sql语句:
SELECT device_id,gender,age,university from user_profile;
输出:
2138|male|21|北京大学 3214|male|None|复旦大学 6543|female|20|北京大学 2315|female|23|浙江大学 5432|male|25|山东大学
1.2 SQL2 查询所有列
题目:现在运营想要查看用户信息表中所有的数据,请你取出相应结果
示例:user_profile
根据示例,你的查询应返回以下结果:
sql语句:
select * from user_profile;
输出:
1|2138|male|21|北京大学|BeiJing 2|3214|male|None|复旦大学|Shanghai 3|6543|female|20|北京大学|BeiJing 4|2315|female|23|浙江大学|ZheJiang 5|5432|male|25|山东大学|Shandong
2. 简单处理查询结果
2.1 SQL3 查询结果去重
题目:现在运营需要查看用户来自于哪些学校,请从用户信息表中取出学校的去重数据。
示例:user_profile
根据示例,你的查询应返回以下结果:
sql语句:
select distinct university from user_profile;
输出:
北京大学 复旦大学 浙江大学 山东大学
2.2 SQL4 查询结果限制返回行数
题目:现在运营只需要查看前2个用户明细设备ID数据,请你从用户信息表 user_profile 中取出相应结果。
示例:
根据输入,你的查询应返回以下结果:
sql语句(方式很多,仅供参考):
select device_id from user_profile limit 0,2;
或:
select device_id from user_profile limit 2;
或:
select device_id from user_profile where id in (1,2);
输出:
2138 3214
2.3 SQL5 将查询后的列重新命名
题目:现在你需要查看2个用户明细设备ID数据,并将列名改为 'user_infors_example',,请你从用户信息表取出相应结果。
示例:user_profile
根据示例,你的查询应返回以下结果:
SQL语句(方式不唯一,仅供参考):
select device_id user_infos_example from user_profile limit 0,2;
或:
select device_id user_infos_example from user_profile limit 2;
输出:
2138 3214