我在clients
表中有2列(还有更多)。
conn_date bill_date
=======================
2016-08-25 2016-09-04
2016-08-01 2016-09-03
2016-08-08 2016-09-01
2016-08-09 2016-09-01
现在我想显示所有数据,如果选择月份=(相等)或>大于conn_date
。我可以从html select tag e中选择月份。 G。 :1,2,9。
为此目的,我正在使用以下查询,但它显示的数据小于conn_date
"SELECT cbp.advance_amount, cbp.bill_month, cbp.due_amount, cbp.pay_amount, c.is_active, c.client_id, c.user_id, c.address, c.contact_no, zone.zone_name, package.package_name, c.monthly_bill, 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.is_active = 1
AND MONTH(c.conn_date) > $selected_month
使用print_r
SELECT cbp.advance_amount, cbp.bill_month, cbp.due_amount, cbp.pay_amount,
c.is_active, c.client_id, c.user_id, c.address, c.contact_no, zone.zone_name, package.package_name, c.monthly_bill, 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 = '6' AND c.is_active = 1
AND MONTH(c.conn_date) > 4 AND c.zone_id != ''
ORDER BY c.client_id DESC
选定的月份图片
答案 0 :(得分:1)
基本上,我想显示的数据不低于所选月份的conn_date
mysql查询是
SELECT * FROM clients WHERE MONTH(conn_date)<='".$selected_month."'
答案 1 :(得分:0)
根据您对问题的描述,听起来像是您想要的:
select c.*
from clients c
where conn_date >= str_to_date(concat(date_format(now(), '%Y-%m'), '-01'))
返回大于当前时间的日期。如果您想要特定年份的特定月份:
select c.*
from clients c
where conn_date >= str_to_date(concat_ws('-', $year, $month, '01'))
我不确定您的查询是做什么的,因为它使用了问题中未提及的几个表。