难题,如何判断同一行数据中的任意列值是否相等?
比如:
a b c d e f g
----------------------------------
001 1 2 1 1 1 1
002 1 1 1 1 1 1
想得到如下:
a b c d e f g
----------------------------------
001 1 2 1 1 1 1
(同一行数据中只要有任意二列不相等,即列出)
------解决方案--------------------select * from 表名 where (not (b=c and c=d and d=e and e=f and f=g)) and b <> null and c <> null and d <> null and e <> null and f <> null and g <> null
这是暂时做法吧,试一下吧。有好的方法再说。暂时没想到。
------解决方案--------------------都正确吧
Select * From TB Where (B <> C OR C <> D OR D <> E OR E <> F OR F <> G)
AND isNull(A, ' ') <> ' ' and isNull(B, ' ') <> ' ' and isNull(C, ' ') <> ' ' and isNull(D, ' ') <> ' '
and isNull(E, ' ') <> ' ' and isNull(F, ' ') <> ' ' and isNull(G, ' ') <> ' '
------解决方案--------------------你的空是指Null還是 ' '
try
Select * From 表 Where a In
(Select a From
(Select a, b As Value From 表
Union All
Select a, c As Value From 表
Union All
Select a, d As Value From 表
Union All
Select a, e As Value From 表
Union All
Select a, f As Value From 表
Union All
Select a, g As Value From 表) A
Where IsNull(Value, ' ') != ' '
Group By a Having Count(Distinct value) > 1)