有人可以帮我解决这个问题。 我有这个样本表:
文件表
我要考虑的是最近上传的30个文件和前30个查看次数最多的文件,然后随机选择并且< strong>限制10 。
我是这个mysql复杂查询的新手。一个示例查询会很好,我将能够理解它。 谢谢。
答案 0 :(得分:2)
SELECT
*
FROM
(
SELECT
*
FROM
tablefile
ORDER BY
uploaded_on_date DESC
LIMIT 30
UNION SELECT
*
FROM
tablefile
ORDER BY
view_count DESC
LIMIT 30
)
ORDER BY
RAND()
LIMIT 10;
答案 1 :(得分:1)
select * from (
select * from table order by upload_on_date desc limit 30
union
select * from table order by view_count desc limit 30) t
order by rand() limit 10