% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/translate-sql-window.R
\name{sql_translation_window}
\alias{sql_translation_window}
\alias{win_over}
\alias{win_rank}
\alias{win_aggregate}
\alias{win_aggregate_2}
\alias{win_recycled}
\alias{win_cumulative}
\alias{win_absent}
\alias{win_current_group}
\alias{win_current_order}
\alias{win_current_frame}
\title{SQL helpers for window functions}
\usage{
win_over(
  expr,
  partition = NULL,
  order = NULL,
  frame = NULL,
  con = sql_current_con()
)

win_rank(f, empty_order = FALSE)

win_aggregate(f)

win_aggregate_2(f)

win_cumulative(f)

win_absent(f)

win_current_group()

win_current_order()

win_current_frame()
}
\arguments{
\item{expr}{The window expression.}

\item{partition}{Variables to partition over.}

\item{order}{Variables to order by.}

\item{frame}{A numeric vector of length two defining the frame.}

\item{con}{A \link{sql_dialect} object or database connection. Connections are
supported for backward compatibility.}

\item{f}{The name of an SQL function as a string.}

\item{empty_order}{A logical value indicating whether to order by NULL if
\code{order} is not specified.}
}
\description{
These functions help you create custom window SQL translations when
implementing a new backend. They are typically used within \code{\link[=sql_translator]{sql_translator()}}
to define how R window functions should be translated to SQL.
\itemize{
\item \code{win_over()} makes it easy to generate the window function specification.
\item \code{win_absent()}, \code{win_rank()}, \code{win_aggregate()}, and \code{win_cumulative()}
provide helpers for constructing common types of window functions.
\item \code{win_current_group()} and \code{win_current_order()} allow you to access
the grouping and order context set up by \code{\link[dplyr:group_by]{group_by()}} and \code{\link[dplyr:arrange]{arrange()}}.
}
}
\examples{
con <- dialect_ansi()

win_over(sql("avg(x)"), con = con)
win_over(sql("avg(x)"), "y", con = con)
win_over(sql("avg(x)"), order = "y", con = con)
win_over(sql("avg(x)"), order = c("x", "y"), con = con)
win_over(sql("avg(x)"), frame = c(-Inf, 0), order = "y", con = con)
}
\seealso{
Other SQL translation helpers:
\code{\link{sql_translation_agg}},
\code{\link{sql_translation_scalar}},
\code{\link{sql_translation_string}},
\code{\link[=sql_variant]{sql_variant()}}
}
\concept{SQL translation helpers}
