SQL SELECT IN数组NodeJS

时间:2018-10-16 08:10:01

标签: mysql node.js express

我有一个结果为['5','2','11','12','4']的数组; 现在,我想基于这种数组来获取计数SQL SELECTION,即执行SELECT IN Array SQL命令。我想从每个元素返回此数组中存在的行数,我尝试过

The SQL Command I tried so far is as in the image provided and my table.

2 个答案:

答案 0 :(得分:0)

您得到的结果恰好是我对COUNT语句的期望。我认为您忘记添加GROUP BY company_two

编辑

要处理公司没有任何条目的情况,您可以执行以下操作:

SELECT s.company_two_id, COUNT(s.id)
FROM supplies_table s
RIGHT OUTER JOIN companies_table c ON s.company_two_id = c.company_id
WHERE company_two_id IN (...)
GROUP BY s.company_two_id;

答案 1 :(得分:0)

尝试以下方法:

select COALESCE(count(a), 0) from table1 where b in (something) group by b