如何在 MySQL 中将行显示为列?
伙计们,我有一个名为beneficiaryloans的表,如下
+----+----------------+--------+--------+------+--------+-----------+ | id | beneficiary_id | hfi_id | amount | rate | period | status_id | +----+----------------+--------+--------+------+--------+-----------+ | 15 | 37 | 116 | 123 | 123 | 123 | 4 | | 16 | 38 | 117 | 123 | 123 | 123 | 4 | | 17 | 39 | 116 | 123 | 123 | 123 | 4 | +----+----------------+--------+--------+------+--------+-----------+
我想根据Hfi_id将其显示如下,
+-----------------+---------------------------+ | beneficiary_id | hfi_id_116 | hfi_id_117 | +-----------------+---------------------------- | 37 | True | False | | 38 | False | True | | 39 | True | False | +----------------------------------------------
如何在MySQL中执行此操作?
注意:这里我发布了一些行,并且hfi_ids在这个表中保留标记,如果3 hfi_id那么我需要3列,如果 4 hfi_ids 那么我需要 4 列 等等
Guys I've table called beneficiaryloans as follows
+----+----------------+--------+--------+------+--------+-----------+ | id | beneficiary_id | hfi_id | amount | rate | period | status_id | +----+----------------+--------+--------+------+--------+-----------+ | 15 | 37 | 116 | 123 | 123 | 123 | 4 | | 16 | 38 | 117 | 123 | 123 | 123 | 4 | | 17 | 39 | 116 | 123 | 123 | 123 | 4 | +----+----------------+--------+--------+------+--------+-----------+
I want to Display It as follows based on Hfi_id
+-----------------+---------------------------+ | beneficiary_id | hfi_id_116 | hfi_id_117 | +-----------------+---------------------------- | 37 | True | False | | 38 | False | True | | 39 | True | False | +----------------------------------------------
How to do this in MySQL?
Note: Here I posted some of rows, and hfi_ids are keep stamping in this table, if 3 hfi_id then i need 3 columns, if 4 hfi_ids then i need 4 columns and so on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
或者如果你需要字符串
Try this:
or if you need strings