带有JOIN的GROUP BY比依赖子查询更有效(在我所知的所有关系数据库中):
Select * From Users
Left Join Photos On (Photos.user_id = Users.id)
Left Join Comments On (Comments.user_id = Users.id)
Group By UserId
Order By (Count(Photos.id) + Count(Comments.id))
Run Code Online (Sandbox Code Playgroud)
对表有一些假设(例如id每个表中的主键).
| 归档时间: |
|
| 查看次数: |
168 次 |
| 最近记录: |