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

示例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 university='山东大学' and gpa>3.5 or university='复旦大学' and gpa>3.8 --虽然短,但是执行用时长 select device_id, gender, age, university, gpa from user_profile where device_id in (select device_id from user_profile where gpa>3.5 and university='山东大学') or device_id in (select device_id from user_profile where gpa>3.8 and university='复旦大学') 复杂的写法,子查询的方式 --运行时间短

select device_id, gender, age, university, gpa from user_profile where device_id in (select device_id from user_profile where university = '复旦大学' and gpa > 3.8)
or
device_id in (select device_id from user_profile where gpa > 3.5 and university = '山东大学')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员豪仔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值