我有一张看起来像那样的 table
foo_date | bar
---------------
2018-01-01 | bar
2018-01-09 | bar
2018-01-10 | bar
2018-01-20 | bar
我想构建一个请求,每周检索本周最先出现的行。
干杯
最佳答案
你可以简单地做:
select distinct on (datetrunc('week', foo_date)) t.*
from t
order by datetrunc('week', foo_date), foo_date;
关于sql - 如何检索每周的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53157426/