我有这个问题:
select
departments.id as id,
departments.active as active,
departments.origin as origin,
TIMESTAMPDIFF (YEAR, origin, CURDATE()) as duration,
CONCAT (departments.name, ' ', departments.section) as name,
GROUP_CONCAT(persons.name SEPARATOR ', ') as persons,
CONCAT (units.type, ' - ', units.name) as unit
from `departments`
inner join `units` on `departments`.`unit_id` = `units`.`id`
left join `department_person` on `departments`.`id` = `department_person`.`department_id`
left join `persons` on `department_person`.`person_id` = `persons`.`id`
where ((departments.id like '%search%')
or (CONCAT (departments.name, ' ', departments.section) like '%search%')
or (TIMESTAMPDIFF (YEAR, origin, CURDATE()) like '%search%')
or (CONCAT (units.type, ' - ', units.name) like '%search%')
or (LOWER(`departments`.`active`) LIKE '%search%')
)
group by `departments`.`id`
having GROUP_CONCAT(persons.name SEPARATOR ', ') LIKE '%search%'
order by `id` asc
limit 10
offset 0
我想在所有选定的字段中执行搜索:ID,活动,来源,持续时间,姓名,单位和人。
一切正常,除非我在人员中添加having GROUP_CONCAT(persons.name SEPARATOR ', ') LIKE '%search'
子句进行搜索。然后,没有任何回报...
您能告诉我如何修改查询以便我可以在人员,group_concat字段内进行搜索吗? 提前谢谢。