我最近遇到一個問題,要求取某一個分類中的任意5條資料,如果此分類資料不足五條則取其他分類資料,補足5條,這個sql應該怎么寫?
uj5u.com熱心網友回復:
思路:select * from
(select *,0 as g from table
where 分類=xxx
limit 5
union all
select *,1 as g from table
where 分類=yyy
limit 5) a
order by g
limit 5
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/23185.html
標籤:MySQL
上一篇:mysql主鍵只有一部分需要自增
下一篇:phpmyadmin登錄后404
