select name as '姓名', count(name) as '同名人数'
from employee
group by name
having count(name) >1 本来就是标准的写法.至于:
select s1.*
from employee s1, employee s2
where s1.name = s2.name and s1.name <> s2.name
我是没有见过这种写法.
where后面的第一个条件为真时,第二个条件永远为假
而where后面的第一个条件为假时,第二个条件永远为真
这条SQL语句是永远都找不出纪录的.你看的这本书不是误人子弟就是你自己看错了!!!
from employee
group by name
having count(name) >1 本来就是标准的写法.至于:
select s1.*
from employee s1, employee s2
where s1.name = s2.name and s1.name <> s2.name
我是没有见过这种写法.
where后面的第一个条件为真时,第二个条件永远为假
而where后面的第一个条件为假时,第二个条件永远为真
这条SQL语句是永远都找不出纪录的.你看的这本书不是误人子弟就是你自己看错了!!!
from employee s1, employee s2
where s1.name = s2.name and s1.num <> s2.num
from employee
group by name
having count(name) >1 是标准的写法,任何情况下都可以用.
而且没有关联,速度快.像這樣的寫法就要根據表結構和數據的情況來.
select s1.*
from employee s1, employee s2
where s1.name = s2.name and s1.num <> s2.num (比方說name也一樣,num也一樣的話,這條SQL語句就有毛病.)