3
我已經爲我的包創建了一個查詢。Mysql多重限制
SQL
SELECT SQL_CALC_FOUND_ROWS DISTINCT * FROM wp_posts
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
WHERE 1=1
AND (((wp_posts.post_title LIKE '% %')
OR (wp_posts.post_content LIKE '% %')))
AND wp_posts.post_type = 'listing_type'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'private')
AND ((wp_postmeta.meta_key = 'packageID'
AND CAST(wp_postmeta.meta_value AS CHAR) = '4'
OR CAST(wp_postmeta.meta_value AS CHAR) = '1'
OR CAST(wp_postmeta.meta_value AS CHAR) = '2'
OR CAST(wp_postmeta.meta_value AS CHAR) = '3'
OR CAST(wp_postmeta.meta_value AS CHAR) = '0'))
GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value ASC, wp_posts.post_date DESC`
這是工作的罰款。但現在我想在每個meta_key
價值中設置限制,因此我可以在我的包中顯示產品。
感謝
SANKET
它工作正常,但我的問題是獲得隨機產品每個meta_value.And的,我需要設置的限制在它。在meta_value ='0'中設置有10個產品,但我想從中顯示兩個隨機記錄。在meta_value ='2'我想從它顯示5個隨機記錄。就像這個我想從SQL獲得。 – sanket