我正在尝试执行SQL查询并收到此错误:
错误:“ rental_date”或附近的语法错误
第4行:选择I.store_id,EXTRACT(从TIMESTAMP出租日期开始的月份)...
这是我的代码:
select
store_id, Month_Name, max(RentOrder) as maximum_order
from
(select
I.store_id, EXTRACT(MONTH FROM TIMESTAMP rental_date) as Month_Name,
count(rental_id) as RentOrder
from
Rental R
inner join
Inventory I on R.inventory_id = I.inventory_id
group by
I.store_id, EXTRACT(MONTH FROM TIMESTAMP rental_date) ) as T
group by
store_id, Month_Name
我检查了与数据库完全匹配的变量名称。
但是,它仍然引发语法问题。协助解决此问题将不胜感激!
答案 0 :(得分:1)
我只是从查询A中删除了时间戳,其余的事情都很好
select
store_id, Month_Name, max(RentOrder) as maximum_order
from
(select
I.store_id, EXTRACT(MONTH FROM rental_date) as Month_Name,
count(rental_id) as RentOrder
from
Rental R
inner join
Inventory I on R.inventory_id = I.inventory_id
group by
I.store_id, EXTRACT(MONTH FROM rental_date) ) as T
group by
store_id, Month_Name
答案 1 :(得分:0)
我假设rental_date
已经是timestamp
。删除TIMESTAMP
个调用中的EXTRACT()
。
...
EXTRACT(MONTH FROM rental_date)
...