[英]how to get the unique records with min and max 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 sql server
. 我在sql server
需要这个结果。 What I need is the minimum of the weight and maximum of the weight and one record 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
Just do a grouping: 只做一个分组:
select id,
max(gender),
max(age),
max([highest weight]),
min([lowest weight]),
max(abc)
from SomeTable
group by id
You can do this using grouping: 您可以使用分组执行此操作:
select id, gender, max(highest_weight), min(lowwest_weight) from student
group by id, gender
But you need do define the rule for the other fields with variable value, like abc 但是您需要为具有变量值的其他字段定义规则,例如abc
Can you post more information? 你能发布更多信息吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.