在 sql 中调用本机函数 'DATEDIFF' 的参数计数不正确
Incorrect parameter count in the call to native function 'DATEDIFF' in sql
根据这个问题应该用什么命令输出:
Display the all values of customers who have joined as members for more than 700 days until today
这是我创建的table:
table Customers
我试过使用 DATEDIFF()
的其他引用,但总是无效 :
SELECT * FROM Customers where DATEDIFF(DAY,customer_join,GETDATE())>700;
在MySQL/MariaDB中,与SQL服务器相反,DATEDIFF()
只接受两个参数,returns一个整数天数他们之间。我们有 timestampdiff()
,它接受三个参数。
此外,getdate()
与 MySQL 无关(这是定制的 SQL 服务器功能)。
你在这里真的不需要日期函数。我会用简单的数据算法来表达这个逻辑:
select *
from customers
where customer_join < current_date - interval 700 day
此表达式可以利用 customer_join
上的索引。
根据您是否要考虑 customer_join
的时间部分(如果有的话),您可能想使用 now()
而不是 current_date
。
根据这个问题应该用什么命令输出:
Display the all values of customers who have joined as members for more than 700 days until today
这是我创建的table:
table Customers
我试过使用 DATEDIFF()
的其他引用,但总是无效 :
SELECT * FROM Customers where DATEDIFF(DAY,customer_join,GETDATE())>700;
在MySQL/MariaDB中,与SQL服务器相反,DATEDIFF()
只接受两个参数,returns一个整数天数他们之间。我们有 timestampdiff()
,它接受三个参数。
此外,getdate()
与 MySQL 无关(这是定制的 SQL 服务器功能)。
你在这里真的不需要日期函数。我会用简单的数据算法来表达这个逻辑:
select *
from customers
where customer_join < current_date - interval 700 day
此表达式可以利用 customer_join
上的索引。
根据您是否要考虑 customer_join
的时间部分(如果有的话),您可能想使用 now()
而不是 current_date
。