我正在尝试在 Postgres 中构建查询。我的背景是 SQL Server,所以我遇到了一些语法挑战。我的查询需要在两个单独的服务器上访问两个单独的数据库。我需要在数据集之间进行连接。本质上,我在 db1 中有一个包含用户登录活动的表。每次用户登录网站时都会添加一个条目。在 db2 上,我有一张购买表。对于每一天,我需要查看:有多少人登录以及有多少登录用户进行了购买。
我的表如下所示:
Logins Purchases
--------- ---------
ID User_ID
User_ID Amount
LoginDate
如果我的采购表上有一个日期字段,这将很容易。但事实并非如此。所以,目前,我正在尝试以下方法:
SELECT
// Somehow get the number of logins for the given day here
// Somehow I need to get the number of purchases for the given day here
TO_CHAR(TO_TIMESTAMP((LoginDate/1000) - 14400), 'MM/DD/YYYY') AS the_day
FROM
db1.Logins AS t1,
db2.Purchases as t2
GROUP BY the_day
ORDER BY the_day;
如何在 Postgres 中获取每天的登录和购买次数?谢谢!