hsSqlExTimeGroup: SQL Expression: Time Grouping

View source: R/sql_expressions.R

hsSqlExTimeGroupR Documentation

SQL Expression: Time Grouping

Description

Generates SQL code for grouping timestamps by years, months or days

Usage

hsSqlExTimeGroup(tbl, tsField, interval, cond = "TRUE")

Arguments

tbl

name of the table

tsField

name of the table field containing the timestamp

interval

specifies the time period to group by ("y": years, "m": months, "d": days)

cond

additional condition in SQL syntax

Value

Returns SQL code for grouping timestamps by years, months or days

See Also

hsSqlExTimeCond

Examples

## Show SQL query that gets the number of datasets per 
## day ("d") considering the condition "Q > 0"
hsSqlExTimeGroup("myTable", "myTimestamp", "d", "Q > 0")
  
## Output (reformatted):  
## SELECT DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) 
##   AS myInterval, Count(*) AS myCount 
## FROM (
##     SELECT myTimestamp AS hsTS FROM myTable WHERE Q > 0
## ) 
## GROUP BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) 
## ORDER BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS))


KWB-R/kwb.db documentation built on Oct. 1, 2023, 4:10 a.m.