开发者社区 问答 正文

从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 584 分享
分享
版权
举报
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 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等