我有一个复杂的查询,当我尝试添加"ORDER BY b.allowed"
时会中断 - 我在哪里可以添加它,为什么它会破坏查询?
$listpage = mysql_query(
"SELECT
LEFT(a.post_content, 80) AS excerpt, a.id,
a.post_title, a.guid,
MAX(CASE WHEN b.meta_key = 'allowed' THEN b.meta_value END) allowed,
MAX(CASE WHEN b.meta_key = 'amenities' THEN b.meta_value END) amenities,
MAX(CASE WHEN b.meta_key = 'trail-type' THEN b.meta_value END) trailtype,
MAX(CASE WHEN b.meta_key = 'miles' THEN b.meta_value END) miles,
MAX(CASE WHEN b.meta_key = '_pronamic_google_maps_latitude'
THEN b.meta_value END) weatherlat,
MAX(CASE WHEN b.meta_key = '_pronamic_google_maps_longitude'
THEN b.meta_value END) weatherlon
FROM
wp_posts a
LEFT JOIN wp_postmeta b ON a.id = b.post_id
WHERE
a.id IN (SELECT object_id AS id FROM wp_term_relationships
WHERE term_taxonomy_id = ". $mycatid .")
group by b.post_id");
答案 0 :(得分:1)
您可以尝试在 group by 子句后添加:
ORDER BY 5
“5”表示在这种情况下,第五个字段(允许)。
我希望它可以帮到你。