限购后再下单 [英] Get another order after limit

查看:65
本文介绍了限购后再下单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我有一个表"users",其中有两个字段:"age"和"name".我想检索前十名年龄较大的用户,然后我要按名称对这十名用户进行排序.

Imagine I've a table 'users' with two fields: 'age' and 'name'. I want to retrieve the top ten older users and then I want this list of ten sorted by name.

是否可以使用MySQL?

Is it possible to do it with MySQL?

我已经尝试过:(不起作用)

I've tried this: (doesn't work)

SELECT * FROM users order by age, name limit 10

推荐答案

使用子选择:

SELECT * FROM
(
    SELECT *
    FROM users
    ORDER BY age DESC
    LIMIT 10
) AS T1
ORDER BY name

内部选择查找要返回的10行,外部选择将它们按正确的顺序放置.

The inner select finds the 10 rows you want to return, and the outer select puts them in the correct order.

这篇关于限购后再下单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆