当前位置:网站首页>MySql 中应该如何将多行数据转为多列数据
MySql 中应该如何将多行数据转为多列数据
2022-07-26 07:11:00 【CSDN问答】
有一个表有如下两个字段
| question_id | content |
|---|---|
| 1111 | 测试内容1 |
| 1111 | 测试内容2 |
| 1111 | 测试内容3 |
| 2222 | 你好,世界 |
| 2222 | 太阳升起 |
我想实现如下业务:
根据 question_id,查询出所有的 content,并将 content 转为一行中的多列,例如我要找 question_id = 1111 的,则最终结果如下:
| question_id | content1 | content2 | content3 |
|---|---|---|---|
| 1111 | 测试内容1 | 测试内容2 | 测试内容3 |
注意:question_id 是需要根据查询条件传入的,且 content 内容是不定的,且根据 question_id 找到的内容也不一定是就 2 行,可能有多行,也就是说不能根据 case when 这种写法判断 content
请问应该如何实现
我的解答思路和尝试过的方法
我想要达到的结果
边栏推荐
- MySQL self incrementing lock
- [Star Project] small hat aircraft War (II)
- Drools(3):Drools基础语法(1)
- “蔚来杯“2022牛客暑期多校训练营1补题记录(ACDGIJ)
- What to pay attention to when using German chicks for the first time
- 优炫数据库JDBC打开日志方式有哪些
- 敏捷整洁之道
- HCIP --- MPLS技术
- [749. Isolate virus]
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 1 supplementary question record (acdgij)
猜你喜欢

404 page best practices to improve user experience

Drools(4):Drools基础语法(2)

Airiot IOT platform enables the container industry to build a welding station information monitoring system

Drools (3): drools basic syntax (1)

Opencv learning basic functions

强网杯2021 pwn 赛题解析——baby_diary

Yolov6 target detection practice: training your own data set (video tutorial)

RGB-T追踪——【数据集基准】GTOT / RGBT210 / RGBT234 / VOT-2019-2020 / LasHeR / VTUAV

文件服务器FastDFS

Curl post request on the server, using postman tool for parameter conversion
随机推荐
Drools (4): drools basic syntax (2)
Advanced Mathematics (Seventh Edition) Tongji University General exercises two person solution
强网杯2021 pwn 赛题解析——baby_diary
Opencv learn read images videos and webcams
Precious metal knowledge: lethal short-term secret script
File server fastdfs
QT监听socket事件,使用QSocketNotifier类
From scratch, we will completely develop an online chess game [Gobang] Based on websocket, and only use dozens of lines of code to complete all the logic.
Exclusive lock
one hundred and twenty-three million one hundred and twenty-three thousand one hundred and twenty-three
Acwing- daily question
Docker modifying the MySQL configuration file attached to the host does not take effect?
从XSS Playload 学习浏览器解码
What are the ways to open the JDBC log of Youxuan database
centos7下的MySQL57版本,遇到一个问题不理解有知道的大shen告知
20220725 convolution in automatic control principle
NPM command
[Star Project] small hat aircraft War (II)
The results of the soft test can be checked, and the entry to query the results of the soft test has been opened in the first half of 2022
With Huawei cloud welink, you can connect to the world even in the countryside