gpt4 book ai didi

sql - 需要合并两个select语句的共同结果

转载 作者:行者123 更新时间:2023-12-04 17:41:29 30 4
gpt4 key购买 nike

我必须从两个 sql 语句的结果中选择常用的列 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

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

我需要选择 c1,c2,c3 在两个查询结果中都相同和常见。

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

最佳答案

从选择列表中删除 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

关于sql - 需要合并两个select语句的共同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905438/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com