【发布时间】:2021-10-01 05:06:41
【问题描述】:
这是代码:
select date_part('month',inspection.idate) as _month, inspector.iname, count(inspector.iname) as num
from inspector,inspection
where inspection.idate>='2021/1/1' and inspector.iid = inspection.iid
group by inspector.iname, _month
order by _month
结果如下: enter image description here
需要显示每个月的前 1 个计数,对于第 6 个月,有 2 个计数相同,需要同时显示。
【问题讨论】:
-
postgresql sql 应该是简单的回答
-
欢迎来到 Stack Overflow。请通过tour 了解 Stack Overflow 的工作原理,并阅读How to Ask 以了解如何提高问题的质量。然后查看meta.stackoverflow.com/questions/271055/… 了解与 SQL 相关的问题。
标签: postgresql greatest-n-per-group