我正在尝试通过比较两个表来获取不同ID的列表。 这是我的查询:
public List<int> GetDistinctCustomerIDs(List<int> ticketIDs)
{
string tIDs = string.Join(",", ticketIDs);
var strSql = "Select distinct a.CustomerID";
strSql += " From Ticket a ";
strSql += " Left Join CustomerContact b On a.CalledInByID = b.ContactID";
strSql += " Where a.TicketID in (?) And b.ContactID is null";
strSql += " UNION";
strSql += " Select distinct a.CustomerID";
strSql += " From Ticket a";
strSql += " Left Join CustomerContact b On a.ForemanID = b.ContactID";
strSql += " Where a.TicketID in (?) And b.ContactID is null";
List<int> IDs = connection.Query<int>(strSql, tIDs).ToList();
return IDs;
}
我得到的预期结果计数为1,但其值始终为0,而不是0。当我在sqlite浏览器中运行查询时,它会显示正确的结果,但在我的代码中却不会。
有帮助吗?