I have a big data table that looks something like this
ID Marker Value1 Value2 ================================ 1 A 10 11 1 B 12 13 1 C 14 15 2 A 10 11 2 B 13 12 2 C 3 A 10 11 3 C 12 13 I want to search this data by the following data, which is user input and not stored in a table:
Marker Value1 Value2 ========================== A 10 11 B 12 13 C 14 14 The result should be something like this:
ID Marker Value1 Value2 Match? ========================================== 1 A 10 11 true 1 B 12 13 true 1 C 14 15 false 2 A 10 11 true 2 B 13 12 true 2 C false 3 A 10 11 true 3 C 12 13 false And ultimately this (the above table is not necessary, it should demonstrate how these values came to be):
ID Matches Percent ======================== 1 2 66% 2 2 66% 3 1 33% I'm searching for the most promising approach to get this to work in SQL (PostgreSQL to be exact).
My ideas:
- Create a temporary table, join it with the above one and group the result
- Use CASE WHEN or a temporary PROCEDURE to only use a single (probably bloated) query
I'm not satisified with either approach, hence the question. How can I compare two tables like these efficiently?

GROUP BY + Countfor the first step... When recordHAVING COUNT > 1thenmatchistrue('B', 13,12)for ID = 2 a match if the user input is('B', 12, 13)?