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

ctehm74n  于 2024-01-05  发布在  Mysql
关注(0)|答案(2)|浏览(282)

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

thtygnil

thtygnil1#

光环兄弟...

  1. SELECT *
  2. FROM your_table
  3. WHERE search_date_1 = (SELECT MAX(search_date_1) FROM your_table)
  4. AND search_date_2 = (SELECT MAX(search_date_2) FROM your_table)
  5. AND search_date_3 = (SELECT MAX(search_date_3) FROM your_table)

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

u0sqgete

u0sqgete2#

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

  1. SELECT table1.jobno AS 'Job. No',
  2. (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',
  3. (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',
  4. (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'
  5. FROM `table1` AS table1
  6. GROUP BY table1.jobno

字符串

相关问题