type
があなたの行動であると仮定するとあなたに似た言語を使用して:あなたは正しい構文を使用してSQL Serverでいると仮定すると、
Select au.user_id, au.total_actions, at.type, at.nb_of_type
From (select user_id, count(id) as total_actions
from actions
group by type
having count(*) > 1
order by count(id) desc
limit 100) As au -- ActiveUser
Inner join (select user_id, type, MAX(count(a.id)) as nb_of_type
from action
group by user_id, type) As at -- ActiveType
On at.user_id = au.user_id
と優れた効率:
WITH ActiveUser (user_id, total_actions)
AS
(
select top 100 user_id, count(id)
from actions
group by type
order by count(id) desc
)
Select au.user_id, au.nb_total_of_actions, t.type, t.nb_of_type
From ActiveUser au
Inner join (select user_id, type, MAX(count(id)) as nb_of_type
from action
group by user_id, type
where user_id in (Select user_id from ActiveUser)
) at -- ActiveType
On at.user_id = au.user_id
DBMSがありますあなたは使っていますか? (いくつかの非ANSI SQLがあります...) – jarlh
'Group By [actionName]'だけを選択してください - アクション名またはタイプの列名が何であってもグループ化してください。 – TheUknown