我有一个使用多个MAX语句的查询,这些语句在使用单个MAX语句时有效。我被卡住了。以下作品:
SELECT
MAX(CASE WHEN meta_key = '_pronamic_google_maps_latitude' THEN meta_value END)lat,
FROM wp_postmeta WHERE post_id IN (SELECT id from wp_posts where post_name = 'Idaho')
但这不是:
SELECT
MAX(CASE WHEN meta_key = '_pronamic_google_maps_latitude' THEN meta_value END)lat,
MAX(CASE WHEN meta_key = '_pronamic_google_maps_longitude' THEN meta_value END)long
FROM wp_postmeta WHERE post_id IN (SELECT id from wp_posts where post_name = 'Idaho')
怎么了?
答案 0 :(得分:1)
由于语法高亮显示long为reserved word,因此您必须将其转义为将其用作别名。 Example
SELECT
MAX(CASE WHEN meta_key = '_pronamic_google_maps_latitude' THEN meta_value END) AS lat,
MAX(CASE WHEN meta_key = '_pronamic_google_maps_longitude' THEN meta_value END) AS `long`
FROM wp_postmeta WHERE post_id IN (SELECT id from wp_posts where post_name = 'Idaho')