当前位置:网站首页>SQL试题
SQL试题
2022-08-03 09:20:00 【嘻哈∠※】
考点1:in的用法
题目:现在运营想要找到学校为北大、复旦和山大的同学进行调研,请你取出相关数据。

select device_id,gender,age,university,gpa
from user_profile
where university in ("北京大学","复旦大学","山东大学")
考点2:or的用法
题目:现在运营想要找到学校为北大或GPA在3.7以上(不包括3.7)的用户进行调研,请你取出相关数据(使用OR实现)


select device_id,gender,age,university,gpa
from user_profile
where university = "北京大学" or gpa > 3.7
考点3:不为空
题目:现在运营想要对用户的年龄分布开展分析,在分析时想要剔除没有获取到年龄的用户,请你取出所有年龄值不为空的用户的设备ID,性别,年龄,学校的信息。

select device_id,gender,age,university
from user_profile
where
age !=""
# 第二种age is not null
考点4:不包含某一项
题目:现在运营想要查看除复旦大学以外的所有用户明细,请你取出相应数据

select device_id,gender,age,university
from user_profile
#where university !="复旦大学"
#where university not like "复旦大学"
where university not in ("复旦大学")
考点5:and和or
题目:现在运营想要找到gpa在3.5以上(不包括3.5)的山东大学用户 或 gpa在3.8以上(不包括3.8)的复旦大学同学进行用户调研,请你取出相应数据

select device_id,gender,age,university,gpa
from user_profile
where (gpa>3.5 and university="山东大学")
or (gpa>3.8 and university="复旦大学")
考点6:like模糊语句
题目:现在运营想查看所有大学中带有北京的用户的信息,请你取出相应数据。

select device_id,age,university
from user_profile
where university like ("%北京%")
#包含北京的 university like ("%北京%")
#以北京开头的 university like ("北京%")
# 以北京结尾的("%北京")
考点7:distinct去重唯一
题目:现在运营需要查看用户来自于哪些学校,请从用户信息表中取出学校的去重数据。

select distinct university from user_profile
考点8:最大值和降序(取第一行数据)
题目:运营想要知道复旦大学学生gpa最高值是多少,请你取出相应数据

法1:通过降序,然后取第一条
select gpa
from user_profile
where university = "复旦大学"
order by gpa DESC limit 1
法2:使用聚合函数取最大值
select max(gpa)
from user_profile
where university = "复旦大学"
边栏推荐
猜你喜欢
随机推荐
Does setting the following sysctl settings require a system reboot?
013-二叉树
多媒体数据处理实验3:图像特征提取与检索
验证浮点数输入
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
STP生成树选举结果查看及验证
What exactly does a firmware engineer do?
Let‘s Encrypt 使用
dflow入门2——Slices
别人都不知道的“好用”网站,让你的效率飞快
【LeetCode】zj面试-把字符串转换成整数
Unity编辑器扩展批量修改图片名称
scala reduce、reduceLeft 、reduceRight 、fold、foldLeft 、foldRight
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
Automated test browser driver download version
MySQL-存储过程-函数-
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
pytorch one-hot tips
【微信小程序】底部有安全距离,适配iphone X等机型的解决方案
php中去重二维数组









