过去一周插入了 table 行中的 Select 行
Select rows from table inserted through the past week
我需要 select 数据库中上周添加的所有行。
这是“前 5 名”页面,应显示过去 7 天内销售最多的产品。我试过了:
SELECT order_id
FROM orders
WHERE order_date BETWEEN DATE_ADD(week,-1,CURRENT_DATE) AND NOW()
哪个returns这个错误:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1,CURRENT_DATE) AND NOW() LIMIT 0, 25' at line 1
我尝试过的其他事情只是相同的查询,但其他语法不适用于此 sql 服务器。
你只需要以下
SELECT order_id FROM orders
WHERE order_date >= NOW() - INTERVAL 1 WEEK
如果您正在使用 Mysql 试试这个来获取上周的数据
SELECT order_id FROM orders WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
我需要 select 数据库中上周添加的所有行。
这是“前 5 名”页面,应显示过去 7 天内销售最多的产品。我试过了:
SELECT order_id
FROM orders
WHERE order_date BETWEEN DATE_ADD(week,-1,CURRENT_DATE) AND NOW()
哪个returns这个错误:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1,CURRENT_DATE) AND NOW() LIMIT 0, 25' at line 1
我尝试过的其他事情只是相同的查询,但其他语法不适用于此 sql 服务器。
你只需要以下
SELECT order_id FROM orders
WHERE order_date >= NOW() - INTERVAL 1 WEEK
如果您正在使用 Mysql 试试这个来获取上周的数据
SELECT order_id FROM orders WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY