我有bellow snippet表格格式。如何在mysql当前月的当前年份中统计总数
表名称: - 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
所以任何的身体会告诉我如何发起查询以得到count_set
当前当月的总计user_id
= 3185。
我已经试过了波纹管查询,但它不工作。
$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'];
}
我已创建查询,但有一些语法错误,你可以引导我使它可行查询: - $ query = mysql_query(“SELECT sum(count_set)AS'meta_sum'FROM wp_lead_count WHERE user_id = $ wp_lead_count_user_id AND DATE(end_date)='$ wp_lead_count_end_date'”)或DIE(mysql_error()); –
'$ wp_lead_count_end_date'的外观如何? – Tarek