Title: A table:
CREATE TABLE ' Tbl_time ' (
' id ' int (ten) unsigned not NULL auto_increment,
' Time ' char (TEN) not NULL DEFAULT ' ',
PRIMARY KEY (' id ')
) Engine=innodb;
Mysql> select * from Tbl_time;
+----+------------+
| ID | Time |
+----+------------+
| 1 | 2015-10-27 |
| 2 | 2015-10-27 |
+----+------------+
But the result I'm hoping for is
2015-10-27,2015-10-28,2015-10-29,2015-10-30 2,0,0,0
and only with SQL statements
Solve:
Mysql> Select A.tmp,if (Time is null,0,count (*)) as Ant from (select ' 2015-10-27 ' as TMP Union SELECT ' 2015-10-28 ' union Select ' 2015-10-29 ' Union select ' 2015-10-30 ') a left join Tbl_time on A.tmp=tbl_time.time Group by A.TMP;
+------------+-----+
| TMP | Ant |
+------------+-----+
| 2015-10-27 | 2 |
| 2015-10-28 | 0 |
| 2015-10-29 | 0 |
| 2015-10-30 | 0 |
+------------+-----+
MySQL displays 0 if it is empty, as defined by its value.