[英]SQL query to find rows with the same value in multiple columns
我想在我的表中查找同一行中各列具有重復值的行
例:
id column_1 column_2 column_3
1 123 44 100
2 555 555 555
3 101 396 100
4 99 99 99
5 123 44 100
我需要一個返回第2&4行的查詢。到目前為止,我僅發現標題相似的問題,即在多個列中查找具有相同值的行(例如返回1&5)。這不是我要查找的內容為:)
這是您的查詢:
SELECT * FROM your_table WHERE column_1 = column_2 AND column_2 = column_3
減法可用於三列:
select *
from mytable
where ( column_1 - column_2 = column_3 - column_2 )
and column_1 = column_2
order by 1;
或最小和最大功能可以一起使用:
select *
from mytable
where greatest(column_1,column_2,column_3) = least(column_1,column_2,column_3)
order by 1;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.