ORDER BY an equal value in MySQL

后端 未结 3 1724
情深已故
情深已故 2020-12-30 15:52

All, I\'ve got the following SQL query as of now:

SELECT * FROM $wpdb->posts
JOIN $wpdb->term_relationships ON $wpdb->term_relationships.object_id=$         


        
3条回答
  •  时光说笑
    2020-12-30 16:07

    SELECT ...
    FROM   ...
    ORDER BY (meta_key='featured' AND meta_value='yes') DESC, postid ASC;
    

    If (meta_key='featured' AND meta_value='yes') for a row, that row will have a 1/TRUE. Otherwise, it will have a 0/FALSE. Hence, sorting descending puts the rows that have TRUE first.

提交回复
热议问题