HOW TO COMPARE MULTIPLE COLUMNS AND ROWS OF A TABLE-POSTGRESQL
[From https://www.appsloveworld.com/postgresql/100/156/how-to-compare-multiple-columns-and-rows-of-a-table ] The user input can be supplied using a VALUES clause in a common table expression and that can then be used in a left join with the actual table. with user_input (marker, value1, value2) as ( values ('A', 10, 11), ('B', 12, 13), ('C', 14, 14) ) select d.id, count(*) filter (where (d.marker, d.value1, d.value2) is not distinct from (u.marker, u.value1, u.value2)), 100 * count(*) filter (where (d.marker, d.value1, d.value2) is not distinct from (u.marker, u.value1, u.value2)) / cast(count(*) as numeric) as pct from data d left join user_input u on (d.marker, d.value1, d.value2) = (u.marker, u.value1, u.value2) group by d.id order by d.id; Returns: id | count | pct ---+-------+------ 1 | 2 | 66.67 2 | 2 | 66.67 3 | 1 | 50.00 Online example: https://rextester.com/OBOOD9042 Edit If the order of the values i...