将 MySQL 查询转换为 PostgreSQL。按天排序()?
Converting MySQL query to PostgreSQL. Order by day()?
我正在将此代码从 MySQL 转换为 PostgreSQL。 PostgreSQL 没有 day()
函数让我的 Order by
工作。有已知的解决方案吗?我想按天对结果进行分组。
{
SELECT to_char(date, 'YYYY-mm-dd') AS date
FROM \"users exercises\"
WHERE userid = $user->id AND (date >= '$begin' AND date <= '$end')
GROUP BY day(date)
ORDER BY date
) UNION ALL (
SELECT to_char(date, 'YYYY-mm-dd') AS date
FROM \"users foods\"
WHERE userid = $user->id AND (date >= '$begin' AND date <= '$end')
GROUP BY day(date)
ORDER BY date
}
MySQL 的 day()
returns 是一个月中的第几天。 PostgreSQL equivalent of that is:
GROUP BY extract(day from "date")
我正在将此代码从 MySQL 转换为 PostgreSQL。 PostgreSQL 没有 day()
函数让我的 Order by
工作。有已知的解决方案吗?我想按天对结果进行分组。
{
SELECT to_char(date, 'YYYY-mm-dd') AS date
FROM \"users exercises\"
WHERE userid = $user->id AND (date >= '$begin' AND date <= '$end')
GROUP BY day(date)
ORDER BY date
) UNION ALL (
SELECT to_char(date, 'YYYY-mm-dd') AS date
FROM \"users foods\"
WHERE userid = $user->id AND (date >= '$begin' AND date <= '$end')
GROUP BY day(date)
ORDER BY date
}
MySQL 的 day()
returns 是一个月中的第几天。 PostgreSQL equivalent of that is:
GROUP BY extract(day from "date")