列表

详情


SQL11. 高级操作符练习(1)

描述

题目:现在运营想要找到男性且GPA在3.5以上(不包括3.5)的用户进行调研,请你取出相关数据。
示例: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
3214 male
复旦大学 4.0
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

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Mysql 解法, 执行用时: 36ms, 内存消耗: 6396KB, 提交时间: 2022-01-01

select device_id ,gender,age,university,gpa from user_profile where gpa>3.5 and gender = 'male'

Mysql 解法, 执行用时: 36ms, 内存消耗: 6400KB, 提交时间: 2022-01-22

select device_id,gender,age,university,gpa
from user_profile
where gender = 'male' and gpa > 3.5

Mysql 解法, 执行用时: 36ms, 内存消耗: 6412KB, 提交时间: 2022-01-25

select device_id,gender,age,university,gpa from user_profile 
where gpa>3.5 and gender="male";

Mysql 解法, 执行用时: 36ms, 内存消耗: 6412KB, 提交时间: 2021-12-31

select device_id,gender,age,university,gpa from user_profile where gender="male"and gpa>3.5

Mysql 解法, 执行用时: 36ms, 内存消耗: 6416KB, 提交时间: 2021-12-18

select device_id,gender,age,university,gpa
from user_profile
where gender='male'
and gpa>'3.5'