2017-03-31 51 views
0

我需要在單個表中選擇max(時間)和一些特定的小時數。我嘗試過這樣的事情。任何想法?如何在IN子句中使用max函數

SELECT * FROM ara WHERE date = '2017-03-31' and time in('07:00:00','13:00:00','19:00:00',max(tme)) order by time desc 

SELECT * FROM ara WHERE date = '2017-03-31' and (time = '07:00:00' or time = '13:00:00' or time = '19:00:00'or time = max(time)) order by time desc 
+0

你要帶那個'MAX(TME)'而來? –

回答

2

假設你從同一ara表中選擇的最長時間,你可以做這樣

SELECT * 
FROM ara 
WHERE date = '2017-03-31' and 
     ( 
      time in ('07:00:00','13:00:00','19:00:00') OR 
      time = (SELECT MAX(time) FROM ara) 
     ) 
ORDER BY time desc 
+0

我不能得到最多的時間,我只得到07:00:00','13:00:00','19:00:00。 –

+0

將樣品數據和預期結果添加到您的問題請 –

+0

對不起,我的問題是錯的,我得到了確切的我想要的謝謝。 –