错误:在PostgreSQL中执行查询时出现语法错误

时间:2018-08-05 06:05:05

标签: sql postgresql

我正在尝试执行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

我检查了与数据库完全匹配的变量名称。

但是,它仍然引发语法问题。协助解决此问题将不胜感激!

2 个答案:

答案 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)
...