SELECT num, COUNT(num) AS amt FROM table WHERE num IN ( SELECT num FROM table WHERE id IN (1,2,3)) GROUP BY num HAVING amt > 1
还有,我怎么才能“777”=〉“2”..而不是'数字' =〉'777''金额' =〉'2'结果呢?谢谢
dm7nw8vv1#
不能对聚合列执行where,必须对这些列使用having。
where
having
SELECT t1.num, COUNT(t1.num) AS amt FROM `table` t1 INNER JOIN `table` t2 ON (t1.num = t2.num) WHERE t2.id IN (1,2,3) GROUP BY t1.num HAVING amt > 1
1条答案
按热度按时间dm7nw8vv1#
不能对聚合列执行
where
,必须对这些列使用having
。