我有下面的摘要表格式。
表格名称:- wp_lead_count_freevendor
id entryid start_date end_date user_id count_set entry_date cancel_set_date
70 11392 2015-12-03 2015-12-03 3185 1 2015-12-03 2015-12-04
71 11393 2015-12-03 2015-12-03 3185 1 2015-12-03 2015-12-04
72 11394 2014-10-01 2014-10-01 3185 1 2014-10-01 2014-10-01
在这里,我想计算总数count_set
栏。按start_date
列WHERE
user_id
= 3185表示的当前月份和年份。
假设start_date
当前年份为2015,当前月份为12:
year month count total
2015 12 2
对于一年中该月的用户ID 3185,count_set
总计= 2
因此,任何机构都会告诉我如何触发查询以获取= 3185的count_set
当月当前年份的总数user_id
。
我已经尝试过波纹管查询,但是它不起作用。
$check_per_month=mysql_query("SELECT DATE_FORMAT(end_date, '%Y') as 'year',
DATE_FORMAT(end_date, '%m') as 'month',
COUNT(id) as 'total'
FROM wp_lead_count_freevendor WHERE user_id=$wp_lead_count_user_id
GROUP BY DATE_FORMAT(end_date, '%Y%m')") OR DIE(mysql_error());
while($row = mysql_fetch_assoc($check_per_month))
{
echo $sql_chk_current_month_count=$row['total'];
}
尝试使用where,year和month方法进行计数,如下所示:
SELECT .... WHERE YEAR(start_date)=2015 AND MONTH(start_date)=12
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句