当前位置:网站首页>牛客刷SQL--4
牛客刷SQL--4
2022-08-01 13:42:00 【小唐同学(๑><๑)】
目录
作者简介:大家好我是小唐同学(๑><๑),大家可以叫我小唐
个人主页:小唐同学(๑><๑)的博客主页
系列专栏:数据库
博友们如果也是新手入门MySQL 我希望大家可以多加练习 MySQL题库在牛客网就有已经给大家附上链接,可以直接点击跳转:点击跳转
牛客网支持ACM模式哦,刷算法题也很推荐哦!!!
下面上文章------》
SQL13 Where in 和Not in
描述
题目:现在运营想要找到学校为北大、复旦和山大的同学进行调研,请你取出相关数据。
示例:user_profile
id device_id gender age university gpa 1 2138 male 21 北京大学 3.4 2 3214 male 复旦大学 4.0 3 6543 female 20 北京大学 3.2 4 2315 female 23 浙江大学 3.6 5 5432 male 25 山东大学 3.8 根据输入,你的查询应返回以下结果:
device_id gender age university gpa 2138 male 21 北京大学 3.4 3214 male 复旦大学 4.0 6543 female 20 北京大学 3.2 5432 male 25 山东大学 3.8 示例1
输入:
drop table if exists user_profile; CREATE TABLE `user_profile` ( `id` int NOT NULL, `device_id` int NOT NULL, `gender` varchar(14) NOT NULL, `age` int , `university` varchar(32) NOT NULL, `province` varchar(32) NOT NULL, `gpa` float); INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing',3.4); INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学','Shanghai',4.0); INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学','BeiJing',3.2); INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学','ZheJiang',3.6); INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学','Shandong',3.8);复制输出:
2138|male|21|北京大学|3.4 3214|male|None|复旦大学|4.0 6543|female|20|北京大学|3.2 5432|male|25|山东大学|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
id device_id gender age university province gpa 1 2138 male 21 北京大学 BeiJing 3.4 2 3214 male NULL 复旦大学 Shanghai 4 3 6543 female 20 北京大学 BeiJing 3.2 4 2315 female 23 浙江大学 ZheJiang 3.6 5 5432 male 25 山东大学 Shandong 3.8 根据输入,你的查询应返回以下结果:(该题对于小数点后面的0不需要计算与统计,后台系统会统一输出小数点后面1位)
device_id gender age university gpa 3214 male NULL 复旦大学 4 5432 male 25 山东大学 3.8 示例1
输入:
drop table if exists user_profile; CREATE TABLE `user_profile` ( `id` int NOT NULL, `device_id` int NOT NULL, `gender` varchar(14) NOT NULL, `age` int , `university` varchar(32) NOT NULL, `province` varchar(32) NOT NULL, `gpa` float); INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing',3.4); INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学','Shanghai',4.0); INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学','BeiJing',3.2); INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学','ZheJiang',3.6); INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学','Shandong',3.8);复制输出:
3214|male|None|复旦大学|4.0 5432|male|25|山东大学|3.8
select device_id,gender,age,university,gpa from user_profile where (gpa>3.5 and university='山东大学')or(gpa>3.8 and university='复旦大学');
边栏推荐
猜你喜欢
随机推荐
This article will take you to thoroughly clarify the working mechanism of certificates in Isito
tensorflow2.0手写数字识别(tensorflow手写体识别)
【无标题】
SQL function SQRT
The obstacles to put Istio into production and how we solve them
六石编程学:问题要面对,办法要技巧,做不好的功能要想办法
免费使用高性能的GPU和TPU—谷歌Colab使用教程
【StoneDB Class】Introduction Lesson 2: Analysis of the Overall Architecture of StoneDB
Efficiency tools to let programmers get off work earlier
HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
让程序员早点下班的效率工具
kubernetes之DaemonSet以及滚动更新
Qt实战案例(56)——利用QProcess实现应用程序重启功能
D - Draw Your Cards(模拟)
库函数的模拟实现(strlen)(strcpy)(strcat)(strcmp)(strstr)(memcpy)(memmove)(C语言)(VS)
NebulaGraph v3.2.0 Performance Report
Six Stones Programming: Problems must be faced, methods must be skillful, and functions that cannot be done well must be solved
论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充
数据挖掘-04
魔众文档管理系统 v5.0.0









