mysql 选择具有多个最高日期的行

ctehm74n  于 12个月前  发布在  Mysql
关注(0)|答案(2)|浏览(214)

我的表中有一些值,
Main Table
我想只选择那些最新/最高日期,结果将像下面的图片:
Result Table
我已经尝试与工会,但它没有达到我的期望

thtygnil

thtygnil1#

光环兄弟...

SELECT *
FROM your_table
WHERE search_date_1 = (SELECT MAX(search_date_1) FROM your_table)
AND search_date_2 = (SELECT MAX(search_date_2) FROM your_table)
AND search_date_3 = (SELECT MAX(search_date_3) FROM your_table)

字符串
请测试此代码,如果正确请接受答案。

u0sqgete

u0sqgete2#

我得到的查询结果是这样的
这是我的SQL查询:

SELECT table1.jobno AS 'Job. No',  

(SELECT CONCAT(`search_date_1`, ' - ', `last_search_by_1`) FROM table1 WHERE id IN (SELECT MAX(id)  FROM table1 WHERE jobno = table1.`jobno` AND search_by_1 != '')) AS 'Search Option 1',

(SELECT CONCAT(`search_date_2`, ' - ', `search_by_2`) FROM table1 WHERE id IN (SELECT MAX(id) FROM table1 WHERE jobno = table1.`jobno` AND search_by_2 != '')) AS 'Search Option 2', 

(SELECT CONCAT(`search_date_3`, ' - ', `search_by_3`) FROM table1 WHERE id IN (SELECT MAX(id) FROM table1 WHERE jobno = table1.`jobno` AND search_by_3 != '')) AS 'Search Option 3'

FROM `table1` AS table1 

GROUP BY table1.jobno

字符串

相关问题