Newbie here in PostgreSQL.
I have some SQL which basically lists a sequence of dates from 2/4/2013 to 10/7/2013.
For example:
select date(generate_series(DATE '20130402', DATE '20131007', interval '1' day))
Output:
"2013-04-02"
"2013-04-03"
"2013-04-04"
"2013-04-05"
"2013-04-06"
Then I have another SQL from myorder table:
select date(date_created) as date_created1, count(id) from myorder group by date_created1 order by date_created1 desc
Output:
"2013-08-12;2"
"2013-08-08";1"
"2013-08-02";1"
"2013-08-01";1"
Basically, this shows the total orders per day.
My question is how do I link the first SQL to the 2nd one, so that it will output date and count sequentially (ordered by date). Also, if no order is found in the "myorder" table, it will show "0" instead.
For Example:
2013-08-11 does not have any order record, so the count column will show "0".
More less like this:
"2013-08-12;2"
"2013-08-11;0"
"2013-08-10;0"
"2013-08-09;0"
"2013-08-08;1"
"2013-08-02;1"
"2013-08-01;1"
Thanks for your help in advance.