How can I extract the month using sqldf package

前端 未结 1 862
没有蜡笔的小新
没有蜡笔的小新 2021-01-23 06:56

I tried to get a view that is based on group by of date by using sqldf package and a month function but I got an error :Error in sqliteSendQuery(con, statement, bind.data)

1条回答
  •  不思量自难忘°
    2021-01-23 07:22

    I suspect you are used to SQL Server, but the sqldf backend being used in your case is SQLite, where there is no MONTH function. Try this instead:

    R> sqldf("SELECT strftime('%m', dateTime) AS Month
                ,SUM(wolfs) AS Wolves
             FROM df
             GROUP BY strftime('%m', dateTime)")
    #    Month Wolves
    #  1    01      6
    #  2    02      5
    #  3    03      3
    #  4    04     12
    #  5    05      7
    #  6    08      7
    #  7    09      7
    

    0 讨论(0)
提交回复
热议问题