我陷入了一个我不知道如何解决的SQL问题。
假设我有一个这样的表格(关于房价的估算):
estimationID | estimationDate | userID | cityID
1 | '2020-01-01' | 123456 | 987654
2 | '2020-12-01' | 135790 | 975310
...
将EstimateDate作为进行估算的日期,userID是进行估算的用户的ID,cityID是进行估算的城市的ID。
我需要获取每个城市每个用户的最大估计数(我不在乎哪个,不需要ID)。
就像是
SELECT cityID,*maximum number of estimations made by one user from this city* FROM estimationsTable GROUP BY cityID
任何想法?
一步步:
查询:
select cityid, max(cnt)
from
(
select cityid, userid, count(*) as cnt
from estimationstable
group by cityid, userid
) counted
group by cityid
order by cityid;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句