两个简单问题,请教!!!
1\
a表里3条数据,b表里4条,使用下面的查询语句,结果返回 12条语句,我试出来了,可是为什么?
Select a.*,b.* from a,b;
2\
select a_name,count(*)”number of employees”
from a,b
where ano = a_no
and count (*) > 5
group by a_name
order by 2 desc;
and count (*) > 5 会引发例外,为什么?
请解释详细点,thanks!
1.对的,笛卡儿积
2.语法错,
select a_name,count(*) ”number of employees”
from a,b where ano = a_no
group by a_name
having count (*) > 5
order by 2 desc;
1.笛卡儿积
2.group by 时,count()要放在having 里.应改成:
select a_name,count(*) ”number of employees”
from a,b where ano = a_no
group by a_name
having count (*) > 5
order by 2 desc;
1、如果没有WHERE条件约束,则结果肯定是12条,笛卡尔乘积运算的结果,既A表的每一条记录对应B表中所有的记录,结果等于记录的乘积。
2、语法错误
select a_name,count(*) ”number of employees”
from a,b where ano = a_no
group by a_name
having count (*) > 5
order by 2 desc;
having必须配合group by 使用,看看关于pl/sql方面的书。