Home  >  Article  >  Backend Development  >  如何用 GROUP BY 查出指定排序分组中值最小的

如何用 GROUP BY 查出指定排序分组中值最小的

WBOY
WBOYOriginal
2016-06-13 12:19:18951browse

怎么用 GROUP BY 查出指定排序分组中值最小的
表结构如下:
--------------------------------------------------
A1                    A2
中国                99
中国                94
中国                95
美国                 88
美国                 70
美国                 94
英国                 79
英国                 92
.........

查询出结果先要按A1指定顺序分组,如(美国,中国,英国)
再求分组中值最小的A2

结果如下----------------------
A1                        A2
美国                     70
中国                     94
英国                     79
------解决思路----------------------

<br />SELECT A1,MIN(A2) AS A2 FROM test GROUP BY A1 ORDER BY find_in_set(A1,'美国,中国,英国');<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn