Postgresql

在 Postgresql 中按 Jalali 日期分組

  • May 10, 2021

我想要GROUP BYjalali 的月份,所有日期在我的數據庫中保存為公曆格式,我發現以下 sql 查詢但按公曆日期分組

SELECT COUNT(reserverow.id), EXTRACT(MONTH FROM reserverow.used_date) as "Month"
FROM reserverow
WHERE reserverow.used_date > '2000-09-28 01:00:00'
GROUP BY EXTRACT(MONTH FROM reserverow.used_date)

最簡單的方法是使用Team Appir 的jalali_utilsPostgreSQL 擴展。然後你可以這樣寫你的查詢:

SELECT COUNT(reserverow.id), EXTRACT(MONTH FROM reserverow.used_date) as "Month"
 FROM reserverow
WHERE reserverow.used_date > '2000-09-28 01:00:00'
GROUP BY JALALI_PART('month', reserverow.used_date)

引用自:https://dba.stackexchange.com/questions/291304