string[] questions= new[] { "2","5","1","11","3","1"};
select description,count(description)
from descriptions
inner join questions
on descriptions.qid=questions.id
where descriptions.question=N'hardtest'
and qid in (?)
group by description
我想在此代码中使用数组作为IN
子句的输入。我怎么能这样做?
qid in ('" + list + "')
答案 0 :(得分:2)
string[] questions = new[] { "2", "5", "1", "11", "3", "1" };
string qids = string.Empty;
questions.All((x) => { qids += "','" + x; return true; });
qids = qids.Substring(2);
string sql = @"
select description, count(description)
from descriptions
inner join questions
on descriptions.qid = questions.id
where descriptions.question = N'hardtest'
and qid in ("+qids+@"')
group by description";