【求教】查询条件下同字段值的另一条件记录,该如何解决

【求教】查询条件下同字段值的另一条件记录SQL code/*--TB1表数据示例:CusIDIDtimesAtimeBtimeCtimeDtypeA-A

【求教】查询条件下同字段值的另一条件记录

SQL code
/*--TB1表数据示例:CusID    IDtimes    Atime    Btime    Ctime    DtypeA-A    1    0    0    23    3A-A    2    30    0    0    1A-A    -1    10    1    120    2B-B    1    0    0    11    3B-B    -1    50    0    0    1--...*/DESC TB1;/*CusID            NOT NULL VARCHAR2(25)                IDtimes            NUMBER(4)  Atime/Btime/Ctime    DATE Dtype            NUMBER(4)*/--求Dtype=2且(Btime+Ctime)>0记录同CusID的、满足的Dtype=1且IDtimes=2的记录行!--求教,谢谢方家~--------<2010.12.21 afternoon>


[解决办法]
SQL code
select count(*) from TB1 twhere t.Dtype=1 and t.IDtimes=2 and       exists(select null from TB1 t1              where t.CusID=t1.CusID and t1.Dtype=2 and (t1.Btime+t1.Ctime)>0)
[解决办法]
SQL code
--其实这句话没怎么明白:--求Dtype=2且(Btime+Ctime)>0记录同CusID的、满足的Dtype=1且IDtimes=2的记录行!select count(*) cnt from TB1 awhere a.Dtype=2 and (a.Btime+a.Ctime)>0 and exists(select 1 from TB1 b where a.CusID=b.CusID and b.Dtype=1 and b.IDtimes=2 )
[解决办法]
探讨
SQL code

/*
--TB1表数据示例:
CusID IDtimes Atime Btime Ctime Dtype
A-A 1 0 0 23 3
A-A 2 30 0 0 1
A-A -1 10 1 120 2
B-B 1 0 0 ……