在Oracle中它会失败,因为hr_descr2有十几列,查询不是ANSI有效,但在MySQL上它返回一个结果集,但不是我期望的结果集。我认为它类似于第二个查询返回的结果集,但它看起来更像是一个select *
select *
from hr_descr2 ds2
group by ds2.titolo
having count(1) > 1
order by titolo;
select titolo, count(1)
from hr_descr2 ds2
group by ds2.titolo
having count(1) > 1
order by titolo;
我期待查询执行此操作:
SELECT
*
FROM
hr_descr2
WHERE
titolo IN (SELECT
titolo
FROM
hr_descr2 ds2
GROUP BY ds2.titolo
HAVING COUNT(1) > 1)
ORDER BY titolo;
答案 0 :(得分:0)
由于您指出第一个查询有效,我将假设hr_descr2
表只有一列:titolo
。否则,由于与group by
一起使用的非聚合值,它应该抛出错误。
因此,它返回一个重复的titolo
个不同值的列表,并告诉您它们出现的次数。