按特定列混合`select`查询结果

时间:2014-01-28 21:06:57

标签: mysql sql

如何通过特定列“混合”select个查询结果?

我有以下查询: SELECT * FROM list WHERE server='1' ORDER BY important DESC, id ASC

以上可以给我:

1. type1
2. type1
3. type1
4. type1
5. type2
6. type2
7. type2
8. type1
9. type2
10. type1

每一行都有一个type列,我想要做的是混合结果以便 查询将考虑ORDER BY important DESC, id AS,但也会将结果“混合”type

例如:

1. type1
5. type2
2. type1
6. type2
3. type1
7. type2
4. type1
9. type2
8. type1
10. type1

我尝试了什么:

SELECT * FROM list WHERE server='1' ORDER BY important DESC, id ASC, RAND(type) 

1 个答案:

答案 0 :(得分:0)

您在id之后按important排序,因此随机性永远不会生效。试试这个:

SELECT *
FROM list
WHERE server='1'
ORDER BY important DESC, rand();

这假设有多种类型具有相同的重要性。

相关问题