我有一个名为clients
的Mysql表,其中一个名为conn_date
的字段包含客户注册日期。
现在我想从此表中获取conn_date
大于注册日期且小于当前日期的数据。
例如如果用户在2016-06-01
上注册,则所有数据都应返回coon_date
大于2016-06-01
且小于当前日期
conn_date列值
2016-06-01
2016-08-30
2016-08-30
2016-07-01
2016-08-03
2016-09-18
Mysql查询
$get_client = "SELECT SUM(cbp.pay_amount) AS total_pay_amount, SUM(cbp.discount_amount) AS total_discount_amount, SUM(cbp.advance_amount) AS total_advance_amount, SUM(cbp.due_amount) AS total_due_amount, cbp.advance_amount, cbp.bill_month, YEAR(cbp.bill_month) AS myBillYear, MONTH(cbp.bill_month) AS myBillMonth, cbp.cbp_id, cbp.due_amount, cbp.pay_amount, c.conn_date, c.status, c.client_id, c.monthly_bill, c.user_id, c.address, c.contact_no, zone.zone_name, package.package_name, c.bill_date FROM clients AS c
LEFT JOIN zone ON zone.zone_id = c.zone_id
LEFT JOIN package ON package.package_id = c.package_id
LEFT JOIN clients_pay_bill AS cbp ON cbp.client_id = c.client_id
WHERE c.uid = '$uid' AND c.conn_date <= CURDATE() ";
if($selected_zone != "all") {
$get_client .= " AND c.zone_id != '' ";
} elseif($selected_zone == "all") {
$get_client .= " AND c.zone_id != '' ";
} else {
$get_client .= " AND c.zone_id = '$selected_zone' ";
}
$get_client .= " GROUP BY c.client_id ORDER BY c.client_id DESC ";
现在它只显示当前月份数据不超过注册日期!
答案 0 :(得分:0)
尝试使用以下查询:
它将返回2016-06-01
和current date
之间的数据记录。
select * from clients where conn_date < CURDATE() and conn_date > '2016-06-01'