使用:
SELECt c.custid FROM CUSTOMER c JOIN INVOICE i ON i.custid = c.custid WHERe i.invoiceid IN (10, 20)GROUP BY c.custid HAVINg COUNT(DISTINCT i.invoiceid) = 2
关键是
i.invoiceid需要计数等于
IN子句中参数的数量。
的使用
COUNT(DISTINCT i.invoiceid)是在对帐务编号和发票编号的组合没有唯一约束的情况下-
如果没有重复的机会,则可以从查询中省略DISTINCT:
SELECt c.custid FROM CUSTOMER c JOIN INVOICE i ON i.custid = c.custid WHERe i.invoiceid IN (10, 20)GROUP BY c.custid HAVINg COUNT(i.invoiceid) = 2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)