[英]Add count to SQL query
I have the following SQL query and php output being run on a mysql database... 我在MySQL数据库上运行以下SQL查询和php输出...
$count0 = $wpdb->get_results("
SELECT *
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'
ORDER BY value
");
foreach ( $count0 as $page ) {
echo $repid_field . ' - ' . $page->form_id . ' - ' . $page->value . ' - ' . $page->lead_id . ' - ' . $page->date_created.'<br/>';
}
This works great but I want to add a count to it so that when it outputs the line it tells me how many of 'value' exists. 这很好用,但是我想给它添加一个计数,以便当它输出行时告诉我存在多少个“值”。
I have had a look at the COUNT function but I am not sure where to add it in 我看过COUNT函数,但不确定在哪里添加它
$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'
ORDER BY value
");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.