MYSQL结合2个查询

时间:2018-01-27 03:04:26

标签: mysql

我对SQL很新,因此这听起来很愚蠢。 我有两个问题。

首先

SELECT
  Tap_Back.*
FROM Tap_Back
WHERE Tap_Back.time > '2018-01-23'

第二

SELECT  
  readingdates.readdate  
FROM readingdates  
WHERE readingdates.readdate <= CURRENT_DATE()  
ORDER BY readingdates.readdate DESC  
LIMIT 1

因此,我不想在First中对日期进行硬编码,而是希望从另一个表中读取它。

1 个答案:

答案 0 :(得分:0)

SELECT Tap_Back.* 
FROM Tap_Back 
WHERE Tap_Back.time > (SELECT readingdates.readdate
  FROM readingdates
  WHERE readingdates.readdate <= CURRENT_DATE()
  ORDER BY readingdates.readdate DESC
  LIMIT 1)

或我的偏好是

SELECT Tap_Back.* 
FROM Tap_Back 
WHERE Tap_Back.time > (SELECT min(readingdates.readdate)
  FROM readingdates
  WHERE readingdates.readdate <= CURRENT_DATE())