当我想在不同的postgresql
中计算数据时,我遇到了问题以下是我的查询。
SELECT COUNT (distinct on (a.userid) a.userid, b.name, a.checktime
FROM checkinout a
LEFT JOIN userinfo b
ON b.userid = a.userid
WHERE a.checktime >= '2017-12-28 06:15:00'
AND a.checktime <= '2017-12-28 07:45:00')
我在#34; 上或附近得到语法错误。
答案 0 :(得分:1)
语法为:
select COUNT(distinct co.userid)
from checkinout co left join
userinfo ui
on ui.userid = co.userid
where ui.checktime >= '2017-12-28 06:15:00' and
ui.checktime <= '2017-12-28 07:45:00';
LEFT JOIN
正在将WHERE
转变为内部联接,所以你不妨这样做:
select COUNT(distinct co.userid)
from checkinout co join
userinfo ui
on ui.userid = co.userid
where ui.checktime >= '2017-12-28 06:15:00' and
ui.checktime <= '2017-12-28 07:45:00';