SELECT DISTINCT和MAX我有行/数据表结构如下在同一个查询
-----------
| SURVEY_ID |
------------
| 1 |
| 2 |
| 2 |
| 3 |
| 4 |
-----------
我想获得不同的ID,并在同一个查询的最大ID。我试过
select distinct(survey_id) as survey_id , max(survey_id) as current
from survey_main
group by survey_id
这似乎没有返回正确的结果。我错过了什么?
编辑:所需的结果
---------------------- | Distinct| Max | ---------------------- | 1 | 4 | | 2 | 4 | | 3 | 4 | | 4 | 4 | ----------------------
你有没有试过这个http://stackoverflow.com/questions/612231/how-can-i-select-rows-with-maxcolumn-value-distinct-by-another-column-in-sql – Mowgli 2013-03-18 20:21:29
你想要吗?所有survey_ids的计数和最大值(两列,一行)? – BellevueBob 2013-03-18 20:22:54
@ ItayMoav-Malimovka我只是不想执行2个单独的查询为次要的事情。每行重复的最大值对我来说都很好。 – 2013-03-18 20:25:03