说我,例如有两列;人和行动。然后,每个人必须完成他们选择的任何动作,最多10次。我想输出一个表格,显示每个名字以及他们各自要完成的动作。
澄清,从下表:
name action
a kick
b throw
a run
c duck
a throw
我想产生输出:
name numactionsleft
a 7
b 9
c 9
我尝试了以下几点:
SELECT name, 10-COUNT(*) as numactionsleft
FROM table
GROUP BY name
HAVING COUNT(*) -- unsure where to go from here or if this is the wrong
-- train of thought entirely
但我不确定如何继续。