php - sql查詢結(jié)果合并的問題
問題描述
問題解答
回答1:從所提供的信息看,如果只是為了單純輸出文章ID,及對應(yīng)的屬性10086和屬性12580的值,那么下面這個簡單的SQL就能實現(xiàn)
SELECT art.id, meta1.meta_value AS meta_key10086, meta2.meta_value AS meta_key12580FROM wp_posts AS art LEFT JOIN wp_postmeta AS meta1 ON meta1.post_id = art.id AND meta1.meta_key = ’10086’ LEFT JOIN wp_postmeta AS meta2 ON meta2.post_id = art.id AND meta2.meta_key = ’12580’回答2:
你要的是不是 GROUP_CONCAT 這個聚合函數(shù)?
回答3:試試用full join行不。未測試:
with m1 as (select * from meta where meta_key = ’10086’), m2 as (select * from meta where meta_key = ’12580’)select case m1.post_id when null then m2.post_id else m1.post_id end as post_id, m1.meta_value as meta_key_10086, m2.meta_value as meta_key_12580from m1 full join m2 on m1.post_id = m2.post_id and m1.meta_key=’10086’ and m2.meta_key=’12580’
相關(guān)文章:
1. macos - 無法source activate python272. 我在導(dǎo)入模板資源時遇到無法顯示的問題,請老師解答下3. MySQL中無法修改字段名的疑問4. css3 讓圖片變成灰色(filter),但針對IE11瀏覽器無效5. 運行python程序時出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯誤?6. html5 - 前端面試碰到了一個緩存數(shù)據(jù)的問題,來論壇上請教一下7. PHPExcel表格導(dǎo)入數(shù)據(jù)庫怎么導(dǎo)入8. html - 網(wǎng)頁的a標簽到底要不要寫上域名?9. css - 移動端 盒子內(nèi)加overflow-y:scroll后 字體會變大10. javascript - react如何獲取offsetX?

網(wǎng)公網(wǎng)安備