I have a mysql table called push_message_info
that I want to filter and then calculate some results. The query to get the results is:
SELECT p.pending, s.success, t.total
FROM
(SELECT count(*) AS pending FROM push_message_info WHERE served < total) AS p,
(SELECT count(*) AS success FROM push_message_info WHERE served = total) AS s,
(SELECT count(*) AS total FROM push_message_info) AS t
;
And the thing is I would like to count only the newest entries. Since it has a datetime field called submit_date
I've thought something like this would work:
SELECT p.pending, s.success, t.total
FROM
(SELECT * FROM push_message_info WHERE DATE(submit_date) > '2017-05-14') AS filtered
(SELECT count(*) AS pending FROM filtered WHERE served < total) AS p,
(SELECT count(*) AS success FROM filtered WHERE served = total) AS s,
(SELECT count(*) AS total FROM filtered) AS t
;
But it throws me the error:
ERROR 1146 (42S02): Table 'unifiedpush.filtered' doesn't exist
How can I filter/limit the original table so that I can apply other queries on that new table?