较急 问一条sql查询语句(50分)

  • 主题发起人 fred_jing
  • 开始时间
F

fred_jing

Unregistered / Unconfirmed
GUEST, unregistred user!
表T
id name
a B
a B
a C
如果同id下name有不同值就输出这个表内容,如果同id下name值相同就不输出
 
select distinct * from T
 
试试下面的方法:
begin
DECLARE lExists int;
Select Count(name) From t Group By id
Into lExists;
if lExists > 1 then
输出这个表内容;
end if;
end;
总之思路是根据id分组统计name,如果大于1则输出表内容。
 
szhcracker谢谢 不能用存储过程阿
 
那你在程序中实现咯:
Select Count(name) From t Group By id
if Result > 1 then
begin
...;
end;
应该不难吧。
 
select * from (select id,count(name) as bb from T group by id) where bb>1
 
aahben的方法 是我想要的 揭帖了 大家都分点 谢谢各位
 

Similar threads

S
回复
0
查看
738
SUNSTONE的Delphi笔记
S
S
回复
0
查看
618
SUNSTONE的Delphi笔记
S
S
回复
0
查看
745
SUNSTONE的Delphi笔记
S
顶部