0

I have two tables.

vehicle
+---------+---------+---------+---------------+-------------+---------+-----------+
|   ID    |  number | country | estimate_desc | description | est_date| entry_date|
+---------+---------+---------+---------------+-------------+---------+-----------+

AND vehicle_history

+---------+---------+---------------+-------------+---------+--------------+
|   ID    |  number | estimate_desc | description | est_date| entry_date   |
+---------+---------+---------------+-------------+---------+--------------+

In the page there is a table with data from vehicle table. Also there is additional column with description history. each time row is edited or added new (you can edit only vehicle data not veh_history) description, estimated_event, est_event_date, entry date is saved into veh_history table. What I need is to get all distinct data from veh_history table not older than 7 days. My attached code is partialy working because, if e.g I fill only description or only est_event I cant get this data. It works when both fields are filled.

$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
                              ";
}

I need to filter distinct values (description, estimate_description) and show these values in one string.

4

1 回答 1

0
concat(group_concat(DISTINCT est.date_estimate SEPARATOR '<BR>'),' - ',group_concat(DISTINCT  est.description_estimate))

我希望这能帮到您。

于 2013-09-16T08:56:31.297 回答