mysql查询(按...排序)很慢

时间:2019-02-21 20:55:02

标签: mysql

当我从另一个表中使用ORDER BY时,它的工作速度非常慢。如何进行查询

SELECT u.*, (SELECT COUNT(id) FROM operations o WHERE o.userId=u.userId and o.status=1) as countOperations FROM users u ORDER BY countOperations

1 个答案:

答案 0 :(得分:0)

您的查询格式不正确。请尝试以下查询:

178

您可能还需要在 select clientid, ROW_NUMBER() OVER ( partition by clientid ORDER BY max(calendar) desc ) from STATS group by clientid 上建立索引,并且可能(您可能不需要)在select col1, col2, ..., coln, count(id) countOperations, SUM(o.sumRUB) sumRUB from users u inner join operations o on o.userId=u.userId and o.status=1 group by col1, col2, ..., coln ORDER BY countOperations