select count(u.name) from a where t.seq=a.seq and rownum=1 有点问题,你是不是想找满足条件的第一条纪录阿?? 要知道rownum在表中是不会随着你查询位置的变化而变化的,有可能你的rownum=1的纪录并不满足 t.seq=a.seq 。。 后面的也是一样。。还有,如果正好有满足条件的纪录,那也肯定只有一条,这样要好一些 select count(u.name) from a where rownum=1 and t.seq=a.seq select t.seq, (select count(u.name) from a where t.seq=a.seq and rownum=1) as total, (select count(u.name) from a where t.seq=a.seq and a.sex='f' and rownum=1) as fmale, (select count(u.name) from a where t.seq=a.seq and a.sex='m' and rownum=1) as male from t order by total desc; 这样查询到的count之可能是0或者1,应该不是你的目的
有点问题,你是不是想找满足条件的第一条纪录阿??
要知道rownum在表中是不会随着你查询位置的变化而变化的,有可能你的rownum=1的纪录并不满足
t.seq=a.seq 。。
后面的也是一样。。还有,如果正好有满足条件的纪录,那也肯定只有一条,这样要好一些
select count(u.name) from a where rownum=1 and t.seq=a.seq select t.seq,
(select count(u.name) from a where t.seq=a.seq and rownum=1) as total,
(select count(u.name) from a where t.seq=a.seq and a.sex='f' and rownum=1) as fmale,
(select count(u.name) from a where t.seq=a.seq and a.sex='m' and rownum=1) as male
from t
order by total desc;
这样查询到的count之可能是0或者1,应该不是你的目的