Learn R Programming

pivot (version 18.4.17)

sql_pivot: Create a Pivot Query

Description

Creates a SQL pivot query. Similar to the tidyr::spread function.

Usage

sql_pivot(con, from, select, key, value, levels, ...)

Arguments

con

a Database connection

from

the from clause

select

variables to select in addition to levels.

key

Variable columns originate from

value

The expression to evaluate to create the values

levels

the levels of key to turn into columns.

...

arguments to pass on or ignore.

Examples

Run this code
# NOT RUN {
library(dbplyr)
query <- sql_pivot( dbplyr::simulate_mssql()
                  , from   = ident('##iris')
                  , select = ident()
                  , key    = ident('Species')
                  , value  = rlang::quo(mean(Petal.Length, na.rm=TRUE))
                  , levels = ident(c('versicolor', 'virginica'))
                  )
sql_render(query)
# }

Run the code above in your browser using DataLab