开发者社区> 问答> 正文

从2列的同一字段中选择

我想创建一个报告,该报告在两列示例的同一字段中显示:

receipt id     infotype        information  
-----------------------------------------------
1              phone number    123
1              comment         no comment 
2              phone number    12346
2              any comment     price is high

结果:

receipt id    phone number    comment   
----------------------------------------------
1             123             no comment 
2             12346           price is high

展开
收起
祖安文状元 2020-01-03 16:35:56 560 0
1 条回答
写回答
取消 提交回答
  • 您可以使用条件聚合

    select receiptid, 
           max(case when infotype='phone number' then information end) as phonenumber,
           max(case when infotype like '%comment%' then information end) as comment
    from tablename
    group by receiptid
    
    2020-01-03 16:36:06
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载