I'm desperately searching a query which gives me all datasets to the following query:
SELECT col1, col2, MAX(col3), MIN(col4) FROM table1 GROUP BY col1, col2
This returns a Table like the following
col 1 | col2 | max(col3) | min(col4)
------ | ------ | --------- | ------
10 | 0.5 | 20 | -5
10 | 0.9 | 30 | -2
What I need is the dataset(the whole row) for each max and min and each entity. I could do this programatically with a query like
SELECT * FROM table1 WHERE col1 = 10 AND (col2 = 0.5 OR col2 = 0.9) AND ((col3 = 20 OR col4 = -5) OR (col3 = 30 OR col4 = -2 ))
which returns me 4 datasets,
but the Query gets more ugly with each added MAX or MIN or GROUP BY(this is what the users do with the program).
Let me try to explain it in one sentence: I'm searching a way of displaying the dataset to each max and min value(not col1,col2) of each unique combination of values of col1 and col2.
Is there a way, to do this in one query?
If you need further details don't fear to comment.
Edit 1
Dataset
id | col 1 | col2 | col3 | col4
---- | ------ | ------ | ------ | ------
0 | 10 | 0.5 | 20 | 0
1 | 10 | 0.5 | 15 | -1
2 | 10 | 0.5 | 17 | 12
3 | 10 | 0.5 | 11 | 3
4 | 10 | 0.5 | 5 | -5
5 | 10 | 0.9 | 10 | 1
6 | 10 | 0.9 | 22 | -1
7 | 10 | 0.9 | 15 | -2
8 | 10 | 0.9 | 30 | 3
Desired Output
id | col 1 | col2 | col3 | col4
---- | ------ | ------ | ------ | ------
0 | 10 | 0.5 | 20 | 0
4 | 10 | 0.5 | 5 | -5
7 | 10 | 0.9 | 15 | -2
8 | 10 | 0.9 | 30 | 3