我有多个列具有相同的值。我想找到超过3列的行ID具有相同的值。
@each column is text/blob
表结构类似于 -
id col1 col2 col3 col4 col5 col6 col7 col8 col9
答案 0 :(得分:3)
Unpivot
数据并检查是否相等,试试这个技巧。
SELECT DISTINCT id
FROM (SELECT id,col1 AS col from Yourtable
UNION ALL
SELECT id,col2 from Yourtable
UNION ALL
SELECT id,col3 from Yourtable
UNION ALL
SELECT id,col4 from Yourtable
Union ALL
.......) A
GROUP BY id,col
HAVING Count(1) > 3