SQL query to group by month part of timestamp

后端 未结 1 2000
猫巷女王i
猫巷女王i 2020-12-30 12:53

I\'m really bad at SQL queries but I\'m learning so please forgive this question.

Here is my current query:

SELECT TIMESTAMP, SUM( electricity ) AS e         


        
相关标签:
1条回答
  • 2020-12-30 13:28
    SELECT month('TIMESTAMP'), SUM( electricity ) AS electricity,  `siteID` 
    FROM table
    WHERE (
    MONTH(  `TimeStamp` ) =10)
    GROUP BY siteID, month('TIMESTAMP')
    

    This will work. One thing that you have to think about is that month is not unique. Oct, 2012, in this case, is the same as Oct 2013. You might want to add another column for year.

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