帮助我使用sql
我在这里有一张桌子: click here to see table我想添加一个新行 像这样的“first name”
meta_key = first_name和相应的meta_value 基本看起来像这样
first name ---------- arnold gear john dude
答案 0 :(得分:2)
尝试
SELECT MIN(CASE WHEN meta_key = 'first_name' THEN meta_value END) first_name,
MIN(CASE WHEN meta_key = 'last_name' THEN meta_value END) last_name
FROM wp_usermeta
WHERE meta_key IN ('first_name','last_name')
GROUP BY user_id
示例输出:
| FIRST_NAME | LAST_NAME | --------------------------- | Patrice | Fitzgerald | | Jhon | Doe | | Mark | (null) |
这是 SQLFiddle 演示