需要结合两个select语句的常见结果

Anu*_*nup 5 sql

我必须从两个sql语句的结果中选择常见的coloumns c1,c2,c3.

1)

select c1, c2, c3,count(c3)  from (select * from form_name
where data_created >'1273446000' and data_creazione<'1274569200')
group by c1,c2, c3 having count(c3)>1
Run Code Online (Sandbox Code Playgroud)

2)

select c1, c2, c3,count(c3)  from (select * from form_name 
where data_created>'1272236400' and data_creazione<'1274569200')
group by c1,c2, c3 having count(c3)>2
Run Code Online (Sandbox Code Playgroud)

我需要选择c1,c2,c3在查询结果中同样和常见.

怎么可能这样做...有人可以帮忙吗?

KM.*_*KM. 5

count(c3)从选择列表中删除它,它可以不同(HAVING子句保证这一点),OP只想比较c1,c2和c3.如果COUNT(c3)列不同,哪些行可以是共同的?没有或一些,它会有所不同.同时删除派生表,它们不是必需的.所以尝试:

select 
    c1, c2, c3  
    from form_name
    where data_created >'1273446000' and data_creazione<'1274569200'
    group by c1,c2, c3 
    having count(c3)>1
INTERSECT
select 
    c1, c2, c3
    from form_name 
    where data_created>'1272236400' and data_creazione<'1274569200'
    group by c1,c2, c3 
    having count(c3)>2
Run Code Online (Sandbox Code Playgroud)