【问题标题】:Convert Row Resultset to Column SQLite将行结果集转换为列 SQLite
【发布时间】:2016-02-16 10:39:34
【问题描述】:

我使用 SQLite 从我的查询中得到这样的结果集

ID    description   value
1      name          john
2.     age            30
3.     location       kl

我想将结果集转换成这样的列

name     age      location
john     30        kl 

我该怎么做?

我正在使用 SQLite 和 javascript,angularjs

谢谢

【问题讨论】:

  • 这是表中的所有行吗?我们如何知道哪个年龄与哪个名字相关联?
  • @sagi 这是表中的所有行。所以所有 d 详细信息都属于 d 同一个用户,只是它是行格式,我想将其转换为列格式
  • 发表了答案,希望这就是你的意思

标签: javascript sql angularjs sqlite


【解决方案1】:

你可以使用这个查询:

SELECT max(case when description = 'name' then value end) as name,
       max(case when description = 'age' then value end) as age,
       max(case when description = 'location' then value end) as location
FROM YourTable(or query..)

【讨论】:

    猜你喜欢
    • 2018-10-08
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多