我正在尝试使这个非常简单的SQL脚本工作:
SELECT
DATE(SEC_TO_TIMESTAMP(created_utc)) date_submission,
COUNT(*) AS num_apples_oranges_submissions
FROM
[fh-bigquery:reddit_comments.2008]
WHERE
(LOWER(body) CONTAINS ('apples')
AND LOWER(body) CONTAINS ('oranges'))
GROUP BY
date_submission
ORDER BY
date_submission
结果如下:
1 2008-01-07 3
2 2008-01-08 1
3 2008-01-09 2
4 2008-01-10 3
5 2008-01-11 2
6 2008-01-13 2
7 2008-01-15 2
8 2008-01-16 3
正如您所看到的,对于没有包含“apples”和“oranges”的提交的日期,而不是返回值0,整个行都会丢失(例如在12日和14日)。
我该如何解决这个问题?我的智慧结束了。谢谢。
答案 0 :(得分:1)
请尝试以下操作,它将返回所有提交日期
SELECT T.TableID,
(SELECT L.Text FROM LookupTable L WHERE L.LookupID = T.StatusID) as StatusText,
(SELECT L.Text FROM LookupTable L WHERE L.LookupID = T.TypeID) as TypeText,
(SELECT L.Text FROM LookupTable L WHERE L.LookupID = T.DocID) as DocText
FROM Table T