[英]Select max and min values on one SQL query
I have a table with (id, value) and I would like to get the max and min values for each id. 我有一个带有(id,value)的表,我想获取每个id的最大值和最小值。 I have used the following without success since I got the same max and min values for every id:
我使用以下方法没有成功,因为每个ID的最大值和最小值都相同:
select max(value) as valmax,
min(value) as valmin
from mytable
Any ideas? 有任何想法吗?
I think you find below query 我想你在下面的查询中找到
select id, max(value) as valmax,
min(value) as valmin
from mytable group by id
Just add group by id
in your query 只需在查询中
group by id
添加group by id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.