简体   繁体   English

Codewars Postgres挑战pg :: syntaxerror

[英]Codewars postgres challenge pg::syntaxerror

I'm doing a SQL challenge on Codewars.com. 我正在Codewars.com上进行SQL挑战。 So far so good. 到现在为止还挺好。

The challenge I'm trying to solve is https://www.codewars.com/kata/calculating-month-over-month-percentage-growth-rate/train/sql 我要解决的挑战是https://www.codewars.com/kata/calculating-month-over-month-percentage-growth-rate/train/sql

And my SQL looks like: 我的SQL看起来像:

select date_trunc('month', created_at)::date as date, 
  count(distinct created_at) as count, 
  100 * (count(*) - lag(count(*), 1) over (order by date)) / lag(count(*), 1) over (order by date)) || '%' as growth
from posts
group by date
order by date asc

however, the server keeps on returning me the PG::SyntaxError: ERROR: subquery in FROM must have an alias 但是,服务器不断向我返回PG::SyntaxError: ERROR: subquery in FROM must have an alias

I'm not an expert with Postgres, but I know that I have alias for date, count, and growth as is expected from the task. 我不是Postgres的专家,但我知道我有日期,计数和增长方面的别名,这是该任务所期望的。

What else am I missing? 我还想念什么?

Any help is welcome. 欢迎任何帮助。

Nevermind, I found an issue. 没关系,我发现了一个问题。 I've had an extra bracket in this line: 我在这一行中有一个额外的括号:

100 * (count(*) - lag(count(*), 1) over (order by date)) / lag(count(*), 1) over (order by date)) || '%' as growth

It should have been: 应该是:

100 * (count(*) - lag(count(*), 1) over (order by date)) / lag(count(*), 1) over (order by date) || '%' as growth

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

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