MySql count() to return 0 if no records found

前端 未结 6 1507
太阳男子
太阳男子 2020-12-17 20:10

I have a set of posts on monthly basis. Now i need an array which contains total records of posts posted in each month. I tried below MySql query, Its working fine, but I wa

6条回答
  •  太阳男子
    2020-12-17 20:58

    If the result set had no posts during that time period, you won't get any results to count, hence why it doesn't show.

    You would need to either join to another table that has all of the year months or fill in the data programmatically when the results are returned. I can't think of another way to do this, but perhaps it's possible.

    Also, as others have said, separate the group by a comma.

提交回复
热议问题