Calculate group functions (count, min, max ...) for a column value without grouping
Let's say I have the following table:
Table users (id, name, age, city)
1 John 26 New York
2 Aaron 31 Dallas
3 Jenifer 35 Dallas
4 Connely 34 New York
And I would like to have a table with all users with their city's minimum user age:
1 John 26 New York 26
2 Aaron 31 Dallas 31
3 Jenifer 35 Dallas 31
4 Connely 34 New York 26
This example is a bit artificial, but I haven't found a better example.
If I use a query like:
SELECT * FROM users MIN (age) GROUP BY city
I will probably get:
1 John 26 New York
2 Aaron 31 Dallas
I'm not sure if it will return lines 1 and 2, but that's not the point: as a result, I need to have all users.
Is it possible?
+3
source to share