SQL2 查询多列

描述

题目:现在运营同学想要用户的设备id对应的性别、年龄和学校的数据,请你取出相应数据

示例:user_profile

|----|-----------|--------|-----|------------|----------|
| id | device_id | gender | age | university | province |
| 1 | 2138 | male | 21 | 北京大学 | Beijing |
| 2 | 3214 | male | | 复旦大学 | Shanghai |
| 3 | 6543 | female | 20 | 北京大学 | Beijing |
| 4 | 2315 | female | 23 | 浙江大学 | Zhejiang |
| 5 | 5432 | male | 25 | 山东大学 | Shandong |

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

|-----------|--------|-----|------------|
| device_id | gender | age | university |
| 2138 | male | 21 | 北京大学 |
| 3214 | male | | 复旦大学 |
| 6543 | female | 20 | 北京大学 |
| 2315 | female | 23 | 浙江大学 |
| 5432 | male | 25 | 山东大学 |

示例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);
INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing');
INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学','Shanghai');
INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学','BeiJing');
INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学','ZheJiang');
INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学','Shandong');

复制输出:

复制代码
device_id|gender|age|university
2138|male|21|北京大学
3214|male|None|复旦大学
6543|female|20|北京大学
2315|female|23|浙江大学
5432|male|25|山东大学

题解

sql 复制代码
SELECT  device_id,gender,age,university
from user_profile
相关推荐
一方热衷.5 小时前
YOLO26-Seg ONNXruntime C++/python推理
开发语言·c++·python
靓仔建6 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
与衫6 小时前
Gudu SQL Omni 技术深度解析
数据库·sql
赶路人儿7 小时前
UTC时间和时间戳介绍
java·开发语言
6+h7 小时前
【java】基本数据类型与包装类:拆箱装箱机制
java·开发语言·python
未来之窗软件服务7 小时前
数据库(九)SQL 模式操作 Excel——东方仙盟练气
数据库·sql·excel·仙盟创梦ide·东方仙盟·数据库修复
未来之窗软件服务9 小时前
幽冥大陆(一百12)js打造json硬件管道——东方仙盟筑基期
开发语言·javascript·算法·json·仙盟创梦ide·东方仙盟·东方仙盟算法
人道领域9 小时前
苍穹外卖:菜品分页查询与删除功能(保姆级详解)
java·开发语言·数据库·后端·spring
EverestVIP9 小时前
c++前置声明的方式与说明
开发语言·c++