MNO PNO PAK
33 44 T
33 44 T
33 44 K
33 45 T
33 46 T
34 46 T
34 47 T
35 47 T你好。我在浪费时间好几个小时。我希望我能找到答案。
我想检索的行中,一个mno有不同的,至少有2个pno。而派克应该永远都是。
因此,对于给定的表,只有valids是:
MNO PNO PAK
33 44 T
33 45 T
33 46 T因为其他的mno没有超过两个不同的pno与'T‘pak。
我尝试过这样做,以获得至少3行有效的不同行:
SELECT distinct e1. mno,e1. pno from emq e1
INNER JOIN emq e2 on (e1.MNO=e2.MNO and e1.PNO <>e2.PNO)
INNER JOIN emq e3 on (e1.MNO=e3.MNO and e2.MNO=e3.MNO
and e1.PNO <>e3.PNO and e2.PNO <>e3.PNO)
where e1.PAK='T' and e2.PAK='T' and e2.pak='T' and exists
(SELECT distinct e4. pno,MNO from
emq e4 where e4.pak='T' group by e4. pno,MNO
having count( distinct e4. pno,HAYMNO) >2);但它做不到。存在部分是对每个mno至少验证3行,但无法完成。例如,为了测试,
选择不同的e4。来自emq e4的pno,其中e4.pak='T‘和HAYMNO=33群由e4.pno
是我干的。检索正确
44 45 46但当我加上有计数时
having count( *) >2发布于 2021-04-29 13:37:16
聚合和having子句如何?
select mno
from emq
group by mno
having min(pno) <> max(pno) and
min(pak) = max(pak) and
min(pak) = 'T';如果您想要原始数据,可以使用join、in或exists返回它们:
select emq.*
from emq join
(select mno
from emq
group by mno
having min(pno) <> max(pno) and
min(pak) = max(pak) and
min(pak) = 'T'
) m
on m.mno = emq.mno;https://stackoverflow.com/questions/67318500
复制相似问题