两种不同结果类型的随机顺序? [关闭]
问题描述:
I have two types of ads. Paid and free. When a zip code is queried all the matching ads are returned along with a designation of free or paid. I want to show the paid ads first, then the free ads next. This is simple enough, but is there a way to randomize the display order for each type separately? A single random sort would place some free ads before some paid ones.
我有两种类型的广告。 付费和免费。 查询邮政编码时,将返回所有匹配的广告以及免费或付费的名称。 我想先显示付费广告,然后再显示免费广告。 这很简单,但有没有办法分别随机化每种类型的显示顺序? 单个随机排序会在某些付费广告之前放置一些免费广告。 p> div>
答
This is the most generic form of the kind of query you need:
SELECT *
FROM the_table
ORDER BY [some_type_field(s)], RAND()
;