牛客-----mysql

查询多列_牛客题霸_牛客网

描述

题目:现在运营同学想要用户的设备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|山东大学

select device_id,gender,age,university

from user_profile

相关推荐
TDengine (老段)19 小时前
TDengine Python 连接器入门指南
大数据·数据库·python·物联网·时序数据库·tdengine·涛思数据
萧曵 丶19 小时前
事务ACID特性详解
数据库·事务·acid
kejiayuan20 小时前
CTE更易懂的SQL风格
数据库·sql
kaico201820 小时前
MySQL的索引
数据库·mysql
清水白石00821 小时前
解构异步编程的两种哲学:从 asyncio 到 Trio,理解 Nursery 的魔力
运维·服务器·数据库·python
资生算法程序员_畅想家_剑魔21 小时前
Mysql常见报错解决分享-01-Invalid escape character in string.
数据库·mysql
PyHaVolask21 小时前
SQL注入漏洞原理
数据库·sql
ptc学习者1 天前
黑格尔时代后崩解的辩证法
数据库
代码游侠1 天前
应用——智能配电箱监控系统
linux·服务器·数据库·笔记·算法·sqlite
!chen1 天前
EF Core自定义映射PostgreSQL原生函数
数据库·postgresql