我的查询结果如下:
+------------------+------------+
| meta_key | meta_value |
+------------------+------------+
| Destination Name | Shivapuri |
| Destination Date | 26/03/2012 |
+------------------+------------+
我正在尝试编写一个select语句,其列名为Destination Name和Destination Date,其各自的值为Shivapuri和'26 / 03/2012'。如何在MY SQL中使用查询?
答案 0 :(得分:1)
这些方面应该做的事情 -
SELECT
GROUP_CONCAT(IF(meta_key = 'Destination Name', meta_value, NULL)) AS `Destination Name`,
GROUP_CONCAT(IF(meta_key = 'Destination Date', meta_value, NULL)) AS `Destination Date`
FROM tbl_name
GROUP BY record_identifier
答案 1 :(得分:1)
SELECT
(CASE WHEN meta_key = 'Destination Name' THEN meta_value END) as name,
(CASE WHEN meta_key = 'Destination Date' THEN meta_value END) as date
FROM `yourtable`