如何在IN子句

时间:2017-03-31 15:04:32

标签: mysql

我需要在单个表格中选择最大(时间)和一些特定时间。我试过这样的事情。任何想法?

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

1 个答案:

答案 0 :(得分: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