我的查询看起来像
SELECT
users.*,
(select count(*)
from user_actions
where status='pending' and user_id = users.id) number_pending
FROM users
order by name
我需要首先显示那些number_pending
计数大于零的记录。你能帮助我如何实现这个目标吗?
答案 0 :(得分:0)
SELECT
u.*, count(a.*) number_pending
FROM users u join user_actions a
on a.user_id = u.id
where a.status='pending'
order by count(a.*) desc
这是你想要做的吗?