0

私は2つのテーブルを持っています。

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 ではなく、車両データのみを編集できます)、説明、estimate_event、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) をフィルタリングし、これらの値を 1 つの文字列で表示する必要があります。

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 に答える