我可以在 MySQL 结果集中包含一个额外的计数器吗?我有以下查询,它返回两列。我需要一个额外的列(仅在结果中)指示结果集中每一行的行。
select orderid, round(sum(unitprice * quantity),2) as value
from order_details
group by orderid
order by 2 desc
limit 10
我需要如下内容:
10865 1 17250.00
11030 2 16321.90
10981 3 15810.00
10372 4 12281.20
10424 5 11493.20
最佳答案
试试这个:
SET @counter = 0;
Select sub.*
FROM
(
select orderid, (@counter := @counter +1) as counter,
round(sum(unitprice * quantity),2) as value
from order_details
group by orderid
) sub
order by 2 desc
关于mysql - 在 MySQL 结果集中包含一个额外的计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12769415/