如果一周内没有找到数据,SQL将返回1.如何让它返回0?
grp <- with(df, cummax(match(StudentAndClass, LETTERS[1:3], nomatch = 0)))
do.call(rbind, lapply(split(df, grp), function(x)
data.frame(Class = x[,1][2:(nrow(x)-1)], Student = x[[1]][1], stringsAsFactors=FALSE)))
答案 0 :(得分:0)
您有外部联接,因此将count(*)
更改为count(reviews.*)
应该这样做,请尝试:
SELECT w.week, COUNT(reviews.*) AS total
FROM (SELECT generate_series(min(DATE_TRUNC('week', created_at)),
max(DATE_TRUNC('week', created_at)),
interval '7 day'
) as week
FROM reviews
) w LEFT JOIN
"reviews"
ON DATE_TRUNC('week', created_at) = w.week
GROUP BY w.week
ORDER BY w.week;