请问 查询table 表中 name相同的 字段  可否以这条语句 
select * from table t1,table t2 where t1.id<>ti.id and t1.username=t2.username这条语句能执行正确吗?请问还有其他语句吗

解决方案 »

  1.   


    这样写可以啊!!这样写不错,但是你把T2写成了ti了。。改一下就好了!select * from table t1,table t2 where t1.id <>t2.id and t1.username=t2.username 
      

  2.   

    楼主的意思是2个表中id不同,名字相同的表? 你的sql是可以运行的。
    select * from table t1,table t2 where t1.id <>t2.id and t1.username=t2.username 
      

  3.   


    是可以的,还可以用select * from (select table.*, count(1) over(partition by name) cnt from table) where cnt < 1;
      

  4.   


    改一下
    select * from (select table.*, count(1) over(partition by name) cnt from table) where cnt = 1;