将表与列表联系起来

sim*_*one 5 mysql sql sqlite

我有一个像这样的值列表:

("UXT8","U61J","U61W","U62U","X82U","U5NF","U635","U526","28FX")
Run Code Online (Sandbox Code Playgroud)

我希望能够从表中提取它们中的每一个在表的字段中出现的次数,即使出现次数为0.

我所期待的是类似的

select key_field, count(*) from table
where key_field in ("UXT8","U61J","U61W","U62U","X82U","U5NF","U635","U526","28FX")
group by key_field;
Run Code Online (Sandbox Code Playgroud)

但有一种左连接效果.

这在sql中是否可行,特别是在sqlite或mysql变体中?

谢谢

DRC*_*RCB 2

我将使用联合来构建内存表而不是列表:

select t.code, count(mytable.unique_id) from 
  (
  select 'UXT8' as code union 
  select 'U61J' as code union 
  select 'U61W' as code union 
  select 'U62U' as code union 
  select 'X82U' as code union 
  select 'U5NF' as code union 
  select 'U635' as code union 
  select 'U526' as code union 
  select '28FX' as code
  ) as t 
 left outer join mytable on t.code = mytable.key_field
 group by t.code
 order by t.code;
Run Code Online (Sandbox Code Playgroud)