[英]DISTINCT GROUP_CONCAT inside CONCAT
我有两张桌子。
vehicle
+---------+---------+---------+---------------+-------------+---------+-----------+
| ID | number | country | estimate_desc | description | est_date| entry_date|
+---------+---------+---------+---------------+-------------+---------+-----------+
AND vehicle_history
+---------+---------+---------------+-------------+---------+--------------+
| ID | number | estimate_desc | description | est_date| entry_date |
+---------+---------+---------------+-------------+---------+--------------+
页面中有一个表格,其中包含车辆表格中的数据。 此外,还有带有描述历史记录的其他列。 每次编辑或添加新行(您只能编辑车辆数据而不是veh_history)描述,估计事件,est_event_date,输入日期均保存到veh_history表中。 我需要从veh_history表中获取所有不超过7天的数据。 我所附的代码是局部有效的,因为例如,如果我仅填写描述或仅填写est_event,则无法获取此数据。 当两个字段都填写时,它起作用。
$this->_sql['select'] = ...main table data
$this->_sql['from'] = ...main table
if (filter checkbox is checked) {
$this->_sql['select'].= " , CONCAT(GROUP_CONCAT(DISTINCT est.date_estimate, ' - ' , est.description_estimate SEPARATOR '<BR>'), '<BR>', GROUP_CONCAT(DISTINCT des.date_entry, ' - ' , des.description SEPARATOR '<BR>')) as description_joined";
$this->_sql['from'].= "LEFT JOIN (SELECT * FROM veh_vehicle_history
WHERE date_estimate > DATE_ADD(NOW(), INTERVAL -7 DAY) AND description_estimate <> '' GROUP BY description_estimate ORDER BY date_estimate DESC )
as est ON est.tractor_unit_id=veh.object_id
LEFT JOIN (SELECT * FROM veh_vehicle_history
WHERE date_entry > DATE_ADD(NOW(), INTERVAL -7 DAY) AND description <> '' GROUP BY description ORDER BY date_entry DESC )
as des ON des.tractor_unit_id=veh.object_id
";
}
我需要过滤不同的值(description,estimate_description),并在一个字符串中显示这些值。
concat(group_concat(DISTINCT est.date_estimate SEPARATOR '<BR>'),' - ',group_concat(DISTINCT est.description_estimate))
我希望这能帮到您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.