Learn R Programming

rsyncrosim (version 1.2.9)

sqlStatement: Construct an SQLite query

Description

Creates SELECT, GROUP BY and WHERE SQL statements. The resulting list of SQL statements will be converted to an SQLite database query by the datasheet() function.

Usage

sqlStatement(
  groupBy = NULL,
  aggregate = NULL,
  aggregateFunction = "SUM",
  where = NULL
)

Arguments

groupBy

Character string or vector of these. Vector of variables (column names) to GROUP BY.

aggregate

Character string of vector of these. Vector of variables (column names) to aggregate using aggregateFunction.

aggregateFunction

Character string. An SQL aggregate function (e.g. SUM, COUNT).

where

Named list. A list of subset variables. Names are column names, and elements are the values to be selected from each column.

Value

Returns a list of SELECT, GROUP BY and WHERE SQL statements used by datasheet() to construct an SQLite database query.

Details

Variables are column names of the datasheet. See column names using datasheet(,empty=TRUE). Variables not included in groupBy, aggregate or where will be dropped from the table. Note that it is not possible to construct a complete SQL query at this stage, because the datasheet() function may add ScenarioID and/or ProjectID to the query.

Examples

Run this code
# NOT RUN {
# Query the total Amount for each combination of ScenarioID, Iteration, Timestep and StateLabelXID,
# including only Timesteps 0,1 and 2, and Iterations 3 and 4.
mySQL <- sqlStatement(
  groupBy = c("ScenarioID", "Iteration", "Timestep", "StateLabelXID"),
  aggregate = c("Amount"), where = list(Timestep = c(0, 1, 2), Iteration = c(3, 4))
)
mySQL
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab