简体   繁体   English

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

[英]ERROR: syntax error while executing query in PostgreSQL

I am attempting a SQL query and getting this error: 我正在尝试执行SQL查询并收到此错误:

ERROR: syntax error at or near "rental_date" 错误:“ rental_date”或附近的语法错误
LINE 4: select I.store_id,EXTRACT(MONTH FROM TIMESTAMP rental_date) ... 第4行:选择I.store_id,EXTRACT(从TIMESTAMP租赁日期开始的MONTH)...

This is my code: 这是我的代码:

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

I have checked the names of the variables thoroughly matching my database. 我检查了与数据库完全匹配的变量名称。

However, it is still throwing the syntax issue. 但是,它仍然引发语法问题。 Assistance would be appreciated to solve this! 协助解决此问题将不胜感激!

i just remove timestam from your query A and rest of the things are fine 我只是从您的查询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

I assume rental_date already is a timestamp . 我认为rental_date已经是一个timestamp Remove the TIMESTAMP in the EXTRACT() calls. EXTRACT()调用中删除TIMESTAMP

...
EXTRACT(MONTH FROM rental_date)
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM