牛客sql题目练习

Sql3描述

题目:现在运营需要查看用户来自于哪些学校,请从用户信息表中取出学校的去重数据。

示例:user_profile

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据示例,你的查询应返回以下结果:

university
北京大学
复旦大学
浙江大学
山东大学
select university 
from user_profile 
group by university;


select distinct university 
from user_profile;

Sql4描述

题目:现在运营只需要查看前2个用户明细设备ID数据,请你从用户信息表 user_profile 中取出相应结果。

示例:

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据输入,你的查询应返回以下结果:

device_id
2138
3214
select device_id 
from user_profile 
limit 0,2;

Sql5描述

题目:现在你需要查看前2个用户明细设备ID数据,并将列名改为 ‘user_infos_example’,,请你从用户信息表取出相应结果。

示例:user_profile

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据示例,你的查询应返回以下结果:

user_infos_example
2138
3214
select device_id as user_infos_example
from user_profile
limit 0,2;

Sql36描述

题目:现在运营想要取出用户信息表中的用户年龄,请取出相应数据,并按照年龄升序排序。

示例:user_profile

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male23复旦大学4
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8
62131male28北京师范大学3.3

根据示例,你的查询应返回以下结果:

device_idage
653420
213821
321423
231523
543225
213128
select device_id,age
from user_profile
order by age;

sql37描述

题目:现在运营想要取出用户信息表中的年龄和gpa数据,并先按照gpa升序排序,再按照年龄升序排序输出,请取出相应数据。用户信息表:user_profile

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male23复旦大学4
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8
62131male28北京师范大学3.3

你的查询应返回以下结果:

device_idgpaage
65343.220
21313.328
21383.421
23153.623
54323.825
3214423
select device_id,gpa,age 
from user_profile
order by gpa,age;

sql38描述

题目:现在运营想要取出用户信息表中对应的数据,并先按照gpa、年龄降序排序输出,请取出相应数据。

示例 user_profile:

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male23复旦大学4
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8
62131male28北京师范大学3.3

根据示例,你的查询应返回以下结果:

device_idgpaage
3214423
54323.825
23153.623
21383.421
21313.328
65433.220
select device_id,gpa,age
from user_profile
order by  gpa desc,age desc;

sql6描述

题目:现在运营想要筛选出所有北京大学的学生进行用户调研,请你从用户信息表中取出满足条件的数据,结果返回设备id和学校。

示例:user_profile

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据示例,你的查询应返回以下结果:

device_iduniversity
2138北京大学
6543北京大学
select device_id,university
from user_profile
where university = '北京大学'

sql7描述

题目:现在运营想要针对24岁以上的用户开展分析,请你取出满足条件的设备ID、性别、年龄、学校。

用户信息表:user_profile

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据输入,你的 查询应返回以下结果:

device_idgenderageuniversity
5432male25山东大学
select device_id,gender,age,university
from user_profile
where age > 24;

sql8描述

题目:现在运营想要针对20岁及以上且23岁及以下的用户开展分析,请你取出满足条件的设备ID、性别、年龄。

用户信息表:user_profile

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据输入,你的查询应返回以下结果:

device_idgenderage
2138male21
6543female20
2315female23
select device_id,gender,age
from user_profile
where age between 20 and 23;

sql9描述

题目:现在运营想要查看除复旦大学以外的所有用户明细,请你取出相应数据

示例:user_profile

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据输入,你的查询应返回以下结果:

device_idgenderageuniversity
2138male21北京大学
6543female20北京大学
2315female23浙江大学
5432male25山东大学
select device_id,gender,age,university
from user_profile
where university != '复旦大学'

sql10描述

题目:现在运营想要对用户的年龄分布开展分析,在分析时想要剔除没有获取到年龄的用户,请你取出所有年龄值不为空的用户的设备ID,性别,年龄,学校的信息。

示例:user_profile

iddevice_idgenderageuniversityprovince
12138male21北京大学Beijing
23214male复旦大学Shanghai
36543female20北京大学Beijing
42315female23浙江大学ZheJiang
55432male25山东大学Shandong

根据输入,你的 查询应返回以下结果:

device_idgenderageuniversity
2138male21北京大学
6543female20北京大学
2315female23浙江大学
5432male25山东大学
select device_id,gender,age,university
from user_profile
where age is not null;

sql11描述

题目:现在运营想要找到男性且GPA在3.5以上(不包括3.5)的用户进行调研,请你取出相关数据。

示例:user_profile

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male复旦大学4.0
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8

根据输入,你的查询应返回以下结果:

device_idgenderageuniversitygpa
3214male复旦大学4.0
5432male25山东大学3.8
select device_id,gender,age,university,gpa
from user_profile
where gender = 'male' and gpa > 3.5;

sql12描述

题目:现在运营想要找到学校为北大或GPA在3.7以上(不包括3.7)的用户进行调研,请你取出相关数据(使用OR实现)

示例:user_profile

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male复旦大学4.0
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8

根据输入,你的查询应返回以下结果:

device_idgenderageuniversitygpa
2138male21北京大学3.4
3214male复旦大学4.0
6543female20北京大学3.2
5432male25山东大学3.8
select device_id,gender,age,university,gpa
from user_profile
where university = '北京大学' or gpa > 3.7;

sql13描述

题目:现在运营想要找到学校为北大、复旦和山大的同学进行调研,请你取出相关数据。

示例:user_profile

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male复旦大学4.0
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8

根据输入,你的查询应返回以下结果:

device_idgenderageuniversitygpa
2138male21北京大学3.4
3214male复旦大学4.0
6543female20北京大学3.2
5432male25山东大学3.8
select device_id,gender,age,university,gpa
from user_profile
where university in ('北京大学','复旦大学','山东大学');

sql14描述

题目:现在运营想要找到gpa在3.5以上(不包括3.5)的山东大学用户 或 gpa在3.8以上(不包括3.8)的复旦大学同学进行用户调研,请你取出相应数据

示例:user_profile

iddevice_idgenderageuniversityprovincegpa
12138male21北京大学BeiJing3.4
23214maleNULL复旦大学Shanghai4
36543female20北京大学BeiJing3.2
42315female23浙江大学ZheJiang3.6
55432male25山东大学Shandong3.8

根据输入,你的查询应返回以下结果:(该题对于小数点后面的0不需要计算与统计,后台系统会统一输出小数点后面1位)

device_idgenderageuniversitygpa
3214maleNULL复旦大学4
5432male25山东大学3.8
select device_id,gender,age,university,gpa
from user_profile
where (gpa > 3.5 and university = '山东大学') or
(gpa > 3.8 and university = '复旦大学')

sql15描述

题目:现在运营想查看所有大学中带有北京的用户的信息,请你取出相应数据。

示例:用户信息表:user_profile

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male复旦大学4.0
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8
62131male28北京师范大学3.3

根据示例,你的查询应返回如下结果:

device_idageuniversity
213821北京大学
654320北京大学
213128北京师范大学
select device_id,age,university
from user_profile
where university like '%北京%'

sql16描述

题目:运营想要知道复旦大学学生gpa最高值是多少,请你取出相应数据

示例:某user_profile表如下:

iddevice_idgenderageuniversitygpa
12234male21北京大学3.2
22235maleNULL复旦大学3.8
32236female20复旦大学3.5
42237female23浙江大学3.3
52238male25复旦大学3.1
62239male25北京大学3.6
72240maleNULL清华大学3.3
82241femaleNULL北京大学3.7

根据输入,你的查询应返回以下结果,结果保留到小数点后面1位(1位之后的四舍五入):

gpa
3.8
select max(gpa)
from user_profile
where university = '复旦大学';

sql17描述

题目:现在运营想要看一下男性用户有多少人以及他们的平均gpa是多少,用以辅助设计相关活动,请你取出相应数据。

示例:user_profile

iddevice_idgenderageuniversitygpa
12138male21北京大学3.4
23214male复旦大学4.0
36543female20北京大学3.2
42315female23浙江大学3.6
55432male25山东大学3.8
62131male28北京师范大学3.3

根据输入,你的查询应返回以下结果,结果保留到小数点后面1位(1位之后的四舍五入):

male_numavg_gpa
43.6
select count(*) as male_num,avg(gpa) as avg_gpa
from user_profile
where gender = 'male';

sql18描述

题目:现在运营想要对每个学校不同性别的用户活跃情况和发帖数量进行分析,请分别计算出每个学校每种性别的用户数、30天内平均活跃天数和平均发帖数量。

用户信息表:user_profile

30天内活跃天数字段(active_days_within_30)

发帖数量字段(question_cnt)

回答数量字段(answer_cnt)

iddevice_idgenderageuniversitygpaactive_days_within_30question_cntanswer_cnt
12138male21北京大学3.47212
23214male复旦大学4.015525
36543female20北京大学3.212330
42315female23浙江大学3.6512
55432male25山东大学3.8201570
62131male28山东大学3.315713
74321male26复旦大学3.69652

第一行表示:id为1的用户的常用信息为使用的设备id为2138,性别为男,年龄21岁,北京大学,gpa为3.4在过去的30天里面活跃了7天,发帖数量为2,回答数量为12

。。。

最后一行表示:id为7的用户的常用信息为使用的设备id为4321,性别为男,年龄26岁,复旦大学,gpa为3.6在过去的30天里面活跃了9天,发帖数量为6,回答数量为52

你的查询返回结果需要对性别和学校分组,示例如下,结果保留1位小数,1位小数之后的四舍五入:

genderuniversityuser_numavg_active_dayavg_question_cnt
male北京大学17.02.0
male复旦大学212.05.5
female北京大学112.03.0
female浙江大学15.01.0
male山东大学217.511.0
select gender,university,
count(*) as user_num,
avg(active_days_within_30) as avg_active_day,
avg(question_cnt) as avg_question_cnt
from user_profile
group by gender,university;

sql19描述

题目:现在运营想查看每个学校用户的平均发贴和回帖情况,寻找低活跃度学校进行重点运营,请取出平均发贴数低于5的学校或平均回帖数小于20的学校。

示例:user_profile

iddevice_idgenderageuniversitygpaactive_days_within_30question_cntanswer_cnt
12138male21北京大学3.47212
23214male复旦大学4.015525
36543female20北京大学3.212330
42315female23浙江大学3.6512
55432male25山东大学3.8201570
62131male28山东大学3.315713
74321female26复旦大学3.69652

第一行表示:id为1的用户的常用信息为使用的设备id为2138,性别为男,年龄21岁,北京大学,gpa为3.4在过去的30天里面活跃了7天,发帖数量为2,回答数量为12
。。。
最后一行表示:id为7的用户的常用信息为使用的设备id为4321,性别为男,年龄26岁,复旦大学,gpa为3.6在过去的30天里面活跃了9天,发帖数量为6,回答数量为52

根据示例,你的查询应返回以下结果,请你保留3位小数(系统后台也会自动校正),3位之后四舍五入:

universityavg_question_cntavg_answer_cnt
北京大学2.500021.000
浙江大学1.0002.000

解释: 平均发贴数低于5的学校或平均回帖数小于20的学校有2个

属于北京大学的用户的平均发帖量为2.500,平均回答数量为21.000

属于浙江大学的用户的平均发帖量为1.000,平均回答数量为2.000

select university,
avg(question_cnt) as avg_question_cnt,
avg(answer_cnt) as avg_answer_cnt
from user_profile
group by university
having avg(question_cnt) < 5 or avg(answer_cnt)  < 20;

sql20描述

题目:现在运营想要查看不同大学的用户平均发帖情况,并期望结果按照平均发帖情况进行升序排列,请你取出相应数据。

示例:user_profile

iddevice_idgenderageuniversitygpaactive_days_within_30question_cntanswer_cnt
12138male21北京大学3.47212
23214male复旦大学4.015525
36543female20北京大学3.212330
42315female23浙江大学3.6512
55432male25山东大学3.8201570
62131male28山东大学3.315713
74321female26复旦大学3.69652

第一行表示:id为1的用户的常用信息为使用的设备id为2138,性别为男,年龄21岁,北京大学,gpa为3.4在过去的30天里面活跃了7天,发帖数量为2,回答数量为12
。。。
最后一行表示:id为7的用户的常用信息为使用的设备id为4321,性别为男,年龄26岁,复旦大学,gpa为3.6在过去的30天里面活跃了9天,发帖数量为6,回答数量为52

根据示例,你的查询应返回以下结果:

universityavg_question_cnt
浙江大学1.0000
北京大学2.5000
复旦大学5.5000
山东大学11.0000
select university, avg(question_cnt) as avg_question_cnt
from user_profile
group by university
order by avg(question_cnt);

sql21描述

题目:现在运营想要查看所有来自浙江大学的用户题目回答明细情况,请你取出相应数据

示例 :question_practice_detail

iddevice_idquestion_idresult
12138111wrong
23214112wrong
33214113wrong
46543114right
52315115right
62315116right
72315117wrong

第一行表示:id为1的用户的常用信息为使用的设备id为2138,在question_id为111的题目上,回答错误

最后一行表示:id为7的用户的常用信息为使用的设备id为2135,在question_id为117的题目上,回答错误

示例:user_profile

iddevice_idgenderageuniversitygpaactive_days_within_30question_cntanswer_cnt
12138male21北京大学3.47212
23214male复旦大学4.015525
36543female20北京大学3.212330
42315female23浙江大学3.6512
55432male25山东大学3.8201570
62131male28山东大学3.315713
74321female26复旦大学3.69652

第一行表示:id为1的用户的常用信息为使用的设备id为2138,性别为男,年龄21岁,北京大学,gpa为3.4在过去的30天里面活跃了7天,发帖数量为2,回答数量为12
。。。
最后一行表示:id为7的用户的常用信息为使用的设备id为4321,性别为男,年龄26岁,复旦大学,gpa为3.6在过去的30天里面活跃了9天,发帖数量为6,回答数量为52

根据示例,你的查询应返回以下结果,查询结果根据question_id升序排序:

img

解释:

根据题目的数据只有1个浙江大学的用户,那么把浙江大学这个用户所有答题数据查询出来就行

SELECT device_id,question_id,result
FROM question_practice_detail
WHERE device_id IN (
    SELECT device_id
    FROM user_profile 
    WHERE university = '浙江大学'
)
ORDER BY question_id;


SELECT q.device_id,question_id,q.result
from question_practice_detail as q,user_profile as u
where q.device_id = u.device_id and u.university = '浙江大学'
ORDER BY question_id;
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值