簡體   English   中英

在BETWEEN子句中使用SQL子查詢獲取日期

[英]Using SQL sub queries in BETWEEN clause for dates

MySQL中的這種多選擇SQL有什么問題:

select *
from license
where license.expirydate between (
   (select monthrange.monthstart from monthrange where id = 1)
   and
   (select monthrange.monthend from monthrange where id = 1)
)

這是您的查詢:

select *
from license
where license.expirydate between ((select monthrange.monthstart from monthrange where id = 1) and 
                                  (select monthrange.monthend from monthrange where id = 1)
                                 )

between的參數不應放在括號中。 嘗試這個:

select *
from license
where license.expirydate between (select monthrange.monthstart from monthrange where id = 1) and 
                                 (select monthrange.monthend from monthrange where id = 1)

當然,您也可以將其表示為join 此答案僅用於注釋語法錯誤:

select l.*
from license l join
     monthrange m
     on l.expirydate between m.monthstart and m.monthend and
        m.id = 1;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM