Where clause for only one table in a left join

前端 未结 4 1452
难免孤独
难免孤独 2020-12-21 06:07

I have two tables, the first is \'actions\' which has columns \'id\' and \'actionname\', the second is \'completedactions\' which has \'userid\' and \'actionid\'. They look

4条回答
  •  暖寄归人
    2020-12-21 06:16

    select 
      actions.id, 
      actions.actionname, 
      count(completedactions.actionid) 
    from actions
    left join completedactions 
      on completedactions.actionid = actions.id and completedactions.userid = 1
    group by 1,2
    

提交回复
热议问题