I have the following table in my database.
# select * FROM matches;
name | prop | rank
------+------+-------
carl | 1 | 4
carl | 2 | 3
carl | 3 | 9
alex | 1 | 8
alex | 2 | 5
alex | 3 | 6
alex | 3 | 8
alex | 2 | 11
anna | 3 | 8
anna | 3 | 13
anna | 4 | 14
(11 rows)
Each person is ranked at work by different properties/criterias called 'prop' and the performance is called 'rank'. The table contains multiple values of (name, prop) as the example shows.
I want to get the candidates that fulfill ALL the requirements: having (prop=1 AND rank > 5) and (prop=3 AND rank >= 8).
Example 1
Input:
(prop=3 AND rank > 4), (prop=4 AND rank > 16)
Result:
name
-----
(none)
Example 2
Input:
(prop=1 AND rank > 6), (prop=2 AND rank > 4)
Result:
name
-----
alex
Example 3
Input:
(prop=1 AND rank > 2), (prop=2 AND rank > 2)
Result:
name
-----
carl
alex
Example 4
Input:
(prop=3 AND rank > 7)
Result:
name
----
carl
alex
anna
How can I do this in SQL?