I am trying to make a query that checks the clients table and returns a count of users with a specific value for the last 30 days, 365 days and All Time.
The all time count is easy:
$stmt = $conn->prepare("SELECT count(id) AS count FROM clients WHERE referred = :refid");
$stmt->bindParam(':refid', $refid);
$stmt->execute();
$totalreferrals = $stmt->fetchAll();
Table:
id | signup | reffered |
----------------------------
2 | 2012-08-24 | 14 |
----------------------------
3 | 2011-10-13 | 14 |
I am not sure if I can combine the query using a UNION or if I should just make three different queries. Any help?
i think you want this in columns and not in rows if so here it is
SQLFiddle http://sqlfiddle.com/#!2/6e6ce/2