当前位置:网站首页>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
请问应该如何实现
我的解答思路和尝试过的方法
我想要达到的结果
边栏推荐
猜你喜欢

从XSS Playload 学习浏览器解码

Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !

你了解MySQL都包含哪些“零件“吗?

20220725 compensator in automatic control principle

Qt:列表框、表格、树形控件

Image annotation software reference

npm 命令

基于C51实现led流水灯

20220725 自动控制原理中的补偿器

Opencv learning drawing shapes and text
随机推荐
Opengauss simple version installation error
Function of hot air pad
Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV
What to pay attention to when using German chicks for the first time
Drools (4): drools basic syntax (2)
mySql建表的基本操作 与常见的函数
文件服务器FastDFS
Is it safe to invest in treasury bonds in 2022? How do individuals buy treasury bonds?
Precious metal knowledge: lethal short-term secret script
常用的cmd指令
Common CMD instructions
Basic operations and common functions of MySQL table creation
Hands on practice - teach you how to make an intelligent fish tank with STM32
What are the ways to open the JDBC log of Youxuan database
Exclusive lock
微信小程序 - 从入门到入土
"Wei Lai Cup" 2022 Niuke summer multi school training camp 1 supplementary question record (acdgij)
[749. Isolate virus]
Solve the problem that Chrome browser is tampered with by drug bullies
How to delete a statement audit log?