表:要求查询出的结果
123456 1 2
123456 2 2
123456 1 2
123456 2 2
654321 1 2
654321 2 2注释: 在这个表中,查询出 门号=2 的 卡号(单个卡号在 (类型=1的个数)=(类型=2的个数)的情况下才能把这个卡号也查出来,单个卡号在 (类型=1的个数)<>(类型=2的个数)的时候不能在查询结果中显示.也就是计算单个卡号在2号门那里有没有平衡,只有(类型=1的个数)=(类型=2的个数)的时候才算平衡的)
高手指导一下吧~~~
用SQL命令实现或用DELPHI代码实现都可以!
123456 1 2
123456 2 2
123456 1 2
123456 2 2
654321 1 2
654321 2 2注释: 在这个表中,查询出 门号=2 的 卡号(单个卡号在 (类型=1的个数)=(类型=2的个数)的情况下才能把这个卡号也查出来,单个卡号在 (类型=1的个数)<>(类型=2的个数)的时候不能在查询结果中显示.也就是计算单个卡号在2号门那里有没有平衡,只有(类型=1的个数)=(类型=2的个数)的时候才算平衡的)
高手指导一下吧~~~
用SQL命令实现或用DELPHI代码实现都可以!
fc ft fdselect *
from t where fc in (
select fc from (
select a.*,b.ft2 from (
select fc,count(*) ft1
from t
where ft=1
group by fc
) a
inner join (
select fc,count(*) ft2
from t
where ft=2
group by fc
) b
on a.fc=b.fc
) a where ft1=ft2
) and fn=2
) and fd=2
from t where fc in (
select fc from (
select a.*,b.ft2 from (
select fc,count(*) ft1 --类型为1,门号为2的数量
from t
where ft=1 and fd=2
group by fc
) a
inner join (
select fc,count(*) ft2 --类型为2,门号为2的数量
from t
where ft=2 and fd=2
group by fc
) b
on a.fc=b.fc
) a where ft1=ft2 --数量要相同
) and fd=2