mysql - 在 BETWEEN 子句中使用 SQL 子查询获取日期

标签 mysql sql

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)

当然,您也可以将其表示为连接。这个答案只是为了评论语法错误:

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

关于mysql - 在 BETWEEN 子句中使用 SQL 子查询获取日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24127571/

相关文章:

php - 使用连接语句和子查询的 CakePHP 查询准备

mysql - 多个属性的sql自连接

mysql - 从单个表中获取前 10 个最近更新或创建的记录

sql - 批量更新插入 SQL Server 2005

java - 处理超出需要的属性

PHP 仅向 SQL 数据库添加一条新记录

mysql - mysql - 如何在没有触发器和手动插入的情况下在插入时生成/自动增加 guid mysql?

mysql - 根据另一列从mysql获取特定记录

mysql - 如何加快MySQL数据库中SQL查询的执行时间?

sql - 是否有表格比较 SQL 命令和 R 命令?