本文介绍了我们应该使用什么查询将 1colmnn 拆分为多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Table name-userdb
id |  name  |  value
1  | fname   | anand
1  | lname   | kumar
1  |city     | bangalore
2  |fname    |mahesh
2  |lname    |sahoo
2  |city     |manglore
3  |fname    |anil
3  |lname    |singh
3  |city     |balasore

我需要点赞

fname  |  lname  |  city
anand  |  kumar  | bangalore
mahesh | sahoo   | manglore
anil   |singh    |balasore

为此请给我 mysql 查询

for this please give me the mysql query

推荐答案

mmm.. EAVS...除了实际实施设计的明显建议之外,您还可以像这样实现您想要的:

mmm.. EAVS...Beyond the obvious suggestions of actually implementing a design, you can achieve what you want like so:

Select Min( Case When name = 'fname' Then value End ) As fname
    , Min( Case When name = 'lname' Then value End ) As lname
    , Min( Case When name = 'city' Then value End ) As city
From MyTable
Group By Id

这篇关于我们应该使用什么查询将 1colmnn 拆分为多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 23:21