vy32
vy32

Reputation: 29655

Include missing dates as "0" in SELECT ... A,count(A) group BY (Google Sheets, or SQL)

I am creating a histogram of dates using SQL and I want to have "0" values for the missing dates. The specific SQL system I'm using is Google Sheets. Here is my example:

enter image description here

What I really want is for it to look like this: enter image description here

Is there any way to do this?

The query that I'm using is SELECT a,COUNT(a) GROUP BY a ORDER BY a.

Is there a way to do what I want?

Upvotes: 0

Views: 500

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269823

Create a column of the dates you want. For instance, you can put in the first date, the right below it have a formula that adds one day, and copy the formula down.

Then, use COUNTIF or a similar function to get the counts you want, e.g.:

=COUNTIF($A$1:$A:$5,"=" & C2)

2

Upvotes: 3

Related Questions