0

How to count columns when parapameter?

I need to count all clients which when you subtract todays date/current(ex; 2013-10-28) to birth_date column(ex; 2001-15-13) returns "<= 6 months"

I have a this mysql query:

$query = 'SELECT  b.record_number,
CONCAT(b.fname," ",b.lname) AS fullname,
province.area_name AS province,
district.area_name AS district,
llg.area_name AS llg,
office.area_name AS office, 
c.clinic_name,
a.feeding_type, 
COUNT(NOW, b.date_birth), - this is my code
b.date_birth,               
FROM tbl_records AS a
JOIN tbl_client AS b ON a.client_id = b.ID
JOIN tbl_clinic AS c ON a.clinic_id = c.ID
JOIN tbl_area AS llg ON c.llg_id = llg.ID
JOIN tbl_area AS district ON llg.parent_ids = district.ID
JOIN tbl_area AS province ON district.parent_ids = province.ID 
JOIN tbl_area AS office ON office.ID = a.office_id
WHERE a.date >= :start_date AND a.date <= :end_date 
AND a.feeding_type <> "NULL" AND a.office_id = :office_id
GROUP BY a.client_id';
4

1 回答 1

0

要获取 MYSQL 中日期之间的差异,您可以使用DATEDIFF

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_datediff

根据您的问题,我认为您正在尝试返回一些间隔并根据该间隔返回一个字符串。您将需要设置一系列IF语句。

https://dev.mysql.com/doc/refman/5.0/en/if.html

更新:

您可以获得月份的差异,PERIOD-DIFF但您需要更改日期的格式。您可以使用GET_FORMAT

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_get-format

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_period-diff

于 2013-10-28T14:17:31.097 回答