How to Display rows as Columns in MySQL?

前端 未结 1 1295
后悔当初
后悔当初 2020-12-18 10:46

Guys I\'ve table called beneficiaryloans as follows

+----+----------------+--------+--------+------+--------+-----------+
| id | beneficiary_id |         


        
相关标签:
1条回答
  • 2020-12-18 11:15

    Try this:

    SELECT beneficiary_id, 
      CASE hfi_id
          WHEN 116 THEN true
          ELSE false
      END AS hfi_id_116,
      CASE hfi_id
          WHEN 117 THEN true
          ELSE false
      END AS hfi_id_117
    FROM your_table
    

    or if you need strings

    SELECT beneficiary_id, 
      CASE hfi_id
          WHEN 116 THEN 'True'
          ELSE 'False'
      END AS hfi_id_116,
      CASE hfi_id
          WHEN 117 THEN 'True'
          ELSE 'False'
      END AS hfi_id_117
    FROM your_table
    
    0 讨论(0)
提交回复
热议问题