牛客-----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

相关推荐
无名修道院几秒前
DVWA 靶场搭建:Windows11(phpstudy 搭建)(步骤 + 截图 + 常见问题)
数据库·网络安全·渗透测试·靶场·php·dvwa·phpstudy
UCoding2 小时前
新能源技术面试 -- 给出一套mysql备份容灾方案
mysql·面试·主从
CodeAmaz2 小时前
MySQL 事务隔离级别详解
数据库·mysql·事务隔离级别
千寻技术帮2 小时前
10398_基于SSM的教学评价管理系统
数据库·mysql·毕业设计·ssm·教学评价
晨星3342 小时前
使用 IntelliJ IDEA 轻松连接 Java 与 MySQL 8 数据库
java·开发语言·数据库
PWRJOY3 小时前
【MySQL】使用mycli查看数据库的基本操作
数据库·mysql
SadSunset3 小时前
(16)Bean的实例化
java·数据库·笔记·spring
JIngJaneIL3 小时前
基于Java + vue干洗店预约洗衣系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
cui_win3 小时前
MySQL 压测实战:sysbench 从入门到精通
数据库·mysql·压测·sysbench
Selegant3 小时前
Docker 搭建 MySQL 主从服务实战操作详解
mysql·docker·容器