mirror of
https://github.com/sqlfluff/sqlfluff
synced 2025-12-17 19:31:32 +00:00
WIP
This commit is contained in:
@@ -490,6 +490,20 @@ class PragmaStatementSegment(BaseSegment):
|
||||
)
|
||||
|
||||
|
||||
class OverClauseSegment(ansi.OverClauseSegment):
|
||||
"""An OVER clause for window functions."""
|
||||
|
||||
match_grammar: Matchable = Sequence(
|
||||
"OVER",
|
||||
OneOf(
|
||||
Ref("SingleIdentifierGrammar"), # Window name
|
||||
Bracketed(
|
||||
Ref("WindowSpecificationSegment", optional=True),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class StatementSegment(ansi.StatementSegment):
|
||||
"""Overriding StatementSegment to allow for additional segment parsing."""
|
||||
|
||||
|
||||
@@ -1 +1,25 @@
|
||||
SELECT a FROM foo LIMIT 10;
|
||||
|
||||
WITH time_cte AS (
|
||||
SELECT
|
||||
branch,
|
||||
created_at,
|
||||
time,
|
||||
cast(time - LAG (time, 1, time) OVER (ORDER BY time) as real) AS time_spent
|
||||
FROM heartbeats h
|
||||
WHERE user_id = ? AND created_at >= DATE('now', 'start of day')
|
||||
ORDER BY id
|
||||
LIMIT -1 OFFSET 1
|
||||
)
|
||||
SELECT
|
||||
branch as name,
|
||||
cast(time_spent as real) as time_spent,
|
||||
cast(time_spent / (SELECT SUM(time_spent) FROM time_cte) as real) as time_percentage
|
||||
FROM (
|
||||
SELECT
|
||||
branch,
|
||||
cast(SUM(time_spent) as real) AS time_spent
|
||||
FROM time_cte
|
||||
GROUP BY branch
|
||||
ORDER BY time_spent DESC
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user