SELECT
tbl.temp_date AS temp_date,
IFNULL(tbr.aCount, 0) AS a,
IFNULL(tbm.bCount, 0) AS b,
IFNULL(
(tbr.aCount) / (tbm.bCount),
0
) AS c
FROM
(
SELECT
@s :=@s + 1 AS _index,
DATE(
DATE_SUB(CURRENT_DATE, INTERVAL @s DAY)
) AS temp_date
FROM
mysql.help_topic h
INNER JOIN (SELECT @s := - 1) temp
WHERE
@s < 30
ORDER BY
temp_date
) AS tbl
LEFT JOIN (
SELECT
COUNT(part_id) AS aCount,
DATE(create_time) createtime
FROM
finished_product
WHERE
is_complete = 1
AND is_finished = 1
AND is_good_product = 1
GROUP BY
createtime
) AS tbr ON tbl.temp_date = tbr.createtime
LEFT JOIN (
SELECT
COUNT(part_id) AS bCount,
DATE(create_time) createtime
FROM
finished_product
WHERE
is_finished = 1
AND is_complete = 1
GROUP BY
createtime
) AS tbm ON tbl.temp_date = tbm.createtime
GROUP BY
tbl.temp_date;