How to get unique records with minimum and maximum for each user
I have the following table:
id gender age highest weight lowest weight abc
a f 30 90 70 1.3
a f 30 90 65 null
a f 30 null null 1.3
b m 40 100 86 2.5
b m 40 null 80 2.5
c f 50 105 95 6.4
I need this result in a sql server
. I need minimum weight and maximum weight and one entry per user.
id gender age highest weight lowest weight abc
a f 30 90 65 1.3
b m 40 100 80 2.5
c f 50 105 95 6.4
+3
Mian Asbat Ahmad
source
to share
2 answers
Just do the grouping:
select id,
max(gender),
max(age),
max([highest weight]),
min([lowest weight]),
max(abc)
from SomeTable
group by id
+4
Giorgi nakeuri
source
to share
You can do this using grouping:
select id, gender, max(highest_weight), min(lowwest_weight) from student
group by id, gender
But you need to define a rule for other variable value fields like abc
Can you post more information?
+2
Rodrigo menezes
source
to share