我的oracle版本是10.2。当标量子查询具有聚合操作时,这很奇怪。我的表名为 t_test 看起来像这样;
t_id t_name
1 1
2 1
3 2
4 2
5 3
6 3
查询字符串看起来像这样;
select t1.t_id,
(select count(t_name)
from (select t2.t_name
from t_test t2
where t2.t_id=t1.t_id
group by t2.t_name)) a
from t_test t1
这个查询的结果是,
t_id a
1 3
2 3
3 3
4 3
5 3
6 3
这很奇怪,以 t1.t_id=1 为例,
select count(t_name)
from (select t2.t_name
from t_test t2
where t2.t_id=1
group by t2.t_name)
结果是 1,不知何故,“where”运算符不起作用,结果与我这样查询的结果完全相同:
select t1.t_id,
(select count(t_name)
from (select t2.t_name
from t_test t2
group by t2.t_name)) a
from t_test t1
为什么?