我正在尝试从返回的表中获取第一个日期时间记录,该表恰好使用此查询存储多个标题:
(这很长,因为我加入了很多桌子......)
SELECT import.title, a_queue.ins_date, a_queue.start_date, a_queue.end_date, pData.up_time
FROM queuedb.a_queue
LEFT JOIN playDB.base_data playlistData ON playlistData.id = a_queue.playlist_id
LEFT JOIN dDb.import_data import ON playlistData.description = import.id
LEFT JOIN dDb.import_proc pData ON pData.a_id = import.a_id
WHERE a_queue.organization = 'sample' AND pData.unique_id is not NULL AND a_queue.ins_date BETWEEN '2016-09-01 00:00:00' AND '2016-09-30 23:59:59';
应该只是这两个..
+---------+--------------------+----------+--------+--------------------+
|title |ins_time |start_date|end_date|up_time |
+---------+--------------------+----------+--------+--------------------+
|Testing 1|2016-09-05 13:45:19 |NULL |NULL |2016-09-21 03:35:08 |
|Testing 4|2016-09-05 15:08:25 |NULL |NULL |2016-09-21 02:00:22 |
+---------+--------------------+----------+--------+--------------------+
我如何实现这一结果..
答案 0 :(得分:0)
试试这个,
如果你想要最少的up_time使用,MIN(up_time)和GROUP BY import.title
SELECT import.title, a_queue.ins_date, a_queue.start_date, a_queue.end_date, MIN(pData.up_time)
FROM queuedb.a_queue
LEFT JOIN playDB.base_data playlistData ON playlistData.id = a_queue.playlist_id
LEFT JOIN dDb.import_data import ON playlistData.description = import.id
LEFT JOIN dDb.import_proc pData ON pData.a_id = import.a_id
WHERE a_queue.organization = 'sample' AND pData.unique_id is not NULL AND a_queue.ins_date BETWEEN '2016-09-01 00:00:00' AND '2016-09-30 23:59:59' GROUP BY import.title;