简体   繁体   English

如何选择子句之后的编号列

[英]how to SELECT numbering column AFTER order by clause

How can I do a MySQL statement that gives off a numbering column based on the ordered criteria? 我如何做一个MySQL语句,该语句根据有序条件发出编号列? For example, with the use of variables I have been able to produce such column, but the numbering process occurs before it is ordered so the results look in return... out of order 例如,使用变量,我已经能够产生这样的列,但是编号过程是在订购之前进行的,因此结果看起来是返回的……乱序

Try to add a counter: 尝试添加一个计数器:

    SELECT  t.field, t.fieldbis 
            @curRow := @curRow + 1 AS row_number
    FROM    table l
    JOIN    (SELECT @curRow := 0) r
    WHERE   t.field > 50
    ORDER BY t.field2

See With MySQL, how can I generate a column containing the record index in a table? 请参阅使用MySQL,如何生成包含表中记录索引的列?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM