一个表有很多字段,下面有两条记录
1、select * from table where id = 1;
2、select * from table where id = 2;
现在我想比较两条记录有相同字段值的个数,除了循环比较外,有没有什么更高效的办法?
1、select * from table where id = 1;
2、select * from table where id = 2;
现在我想比较两条记录有相同字段值的个数,除了循环比较外,有没有什么更高效的办法?
select count
=case when a.c1 = b.c1 then 1 else 0 end
+...
+case when a.cn = b.cn then 1 else 0 end
from table a,table b
where a.id = 1 and b.id = 2
from (select * from table where id = 1) cross join (select * from table where id = 2)
from (select * from table where id = 1) as tb1 cross join (select * from table where id = 2) as tb2