我有个疑问
select id, item, date producer from table其结果如下:
id item producer date
1 apple A 2013-10-26
2 pear A 2013-10-26
3 peach A 2013-10-26
4 orange B 2013-10-26
5 strawberry B 2013-10-27
6 melon B 2013-10-27
7 apple2 A 2013-10-27
8 orange3 A 2013-10-27我需要对这些数据“按日期订购”进行洗牌,并得到如下内容:
item producer
orange3 A
melon B
apple2 A
strawberry B
pear A
orange B
apple A
peach A
melon B我不想这样展示:
所有的东西..。所有的B物品..。或者洗牌今天加了什么昨天加了什么..。在我的例子中,我不想在"orange3“之前显示”橙色“
我的解决方案(但非常慢)
Select * from table where date = $date order by rand;
Select * from table where date = $date -1 order by rand;
select * from table where date = $date -2 order by rand;(这只是一个概念,不能用这种方法减少$date )
发布于 2013-10-27 18:34:18
看看下面的内容是否对您有好处:
SELECT *
FROM `table`
ORDER BY `date` DESC, RAND()我刚试过了,它似乎做了我认为你想做的事。
编辑
如果您想要持久化“洗牌”,然后添加一个类型为rnd类型的列,请执行
UPDATE `table` SET rnd = RAND()然后在SELECT语句中使用
.... ORDER BY `date` DESC, `rnd`https://stackoverflow.com/questions/19621360
复制相似问题