当前位置:网站首页>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
请问应该如何实现
我的解答思路和尝试过的方法
我想要达到的结果
边栏推荐
- < II> ObjectARX development: create and edit basic graphic objects
- 20220725 自动控制原理中的卷积Convolution
- [romance understood by technical talents] tidb community has prepared a gift for your partner for the "Tanabata Festival". Reply: if I want to challenge, I can participate in the activity!
- [arm learning (8) AXF tool analysis]
- Intention lock
- shape 和 size() 区别
- String and memory functions
- Kernel pwn 入门 (5)
- Realization of LED water lamp based on C51
- 屏:框贴、0贴合、全贴合
猜你喜欢

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

C51与MDK共存 Keil5安装教程

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

Image annotation software reference

HCIP --- MPLS技术

Opencv learning basic functions

Drools (3): drools basic syntax (1)

On the difference between Eval and assert

Opencv learning warp Perspective
![[untitled] reprint](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled] reprint
随机推荐
String and memory functions
QT listens for socket events and uses qsocketnotifier class
WPS or office compression of ppt
How to use Hyper-V in win10 Home Edition
20220725 compensator in automatic control principle
[hard ten treasures] - 7.2 [dynamic RAM] analysis of the difference between DDR4 and DDR3
【一库】妙啊!这个库组织npm脚本简直爆炸!
Huffman coding principle
Common programming shortcut keys of idea (take off after learning the operation)
NIO实现
Advanced Mathematics (Seventh Edition) Tongji University General exercises two person solution
[untitled] reprint
RGB-T追踪——【数据集基准】GTOT / RGBT210 / RGBT234 / VOT-2019-2020 / LasHeR / VTUAV
Business secret series -- Talking about the evaluation of commercial passwords from the perspective of Party A and Party B (I)
解决 Chrome 浏览器被毒霸篡改问题
20220725 自动控制原理中的补偿器
Can you learn fast and well with dual stream network? Harbin Institute of Technology & Microsoft proposed a distillation dual encoder model for visual language understanding, which can achieve fast an
10 papers of ant security laboratory were included by ccf-a top meeting to explore the realization of AI credibility from the perspective of algorithm
File server fastdfs
Shared lock