I have a SQL query I am running on a mysql database that looks like this...
$count0 = $wpdb->get_results("
SELECT *, COUNT(*) as TotalValueCount
FROM
wp_rg_lead
INNER JOIN wp_rg_lead_detail ON
wp_rg_lead.id=wp_rg_lead_detail.lead_id
WHERE wp_rg_lead.form_id = '46'
AND cast(date_created as date) >= current_date - interval '7' day
AND field_number = '18'
GROUP BY value
");
foreach ( $count0 as $page ) {
echo $repid_field . ' - ' . $page->form_id . ' - ' . $page->value . ' - ' . $page->lead_id . ' - ' . $page->date_created.' - ' . $page->TotalValueCount. '<br/>';
What I want to do with this however is return a count for each value for each of the previous 7 days, so I can get results something like this...
value | 01/01/2014 | 01/01/2014 | 01/01/2014
--------------------------------------------------
AA01 34 23 12
BR65 3 65 65
YR76 45 12 65
Is this something I would need to do with the php function afterwards or can this be done with the SQL query itself?