sql_pivot: Create a Pivot Query

Description Usage Arguments Examples

Description

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

Usage

1
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

1
2
3
4
5
6
7
8
9
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)

pivot documentation built on May 2, 2019, 2:02 p.m.