2013-10-08 44 views

回答

5
select * from (select * from your_table 
       where level = 1 order by rand() limit 4) x 
union all 
select * from (select * from your_table 
       where level = 2 order by rand() limit 4) y 
0

嘗試像這樣...

SELECT product_id, title, description FROM products WHERE active = 1 AND stock > 0 ORDER BY RAND() LIMIT 4;