在 postgresql 中按月和年對查詢結果進行分組 - Group query results by month and year in postgresql

問題:

I have the following database table on a Postgres server:我在 Postgres 服務器上有以下數據庫表:

id      date          Product Sales
1245    01/04/2013    Toys    1000     
1245    01/04/2013    Toys    2000
1231    01/02/2013    Bicycle 50000
456461  01/01/2014    Bananas 4546

I would like to create a query that gives the SUM of the Sales column and groups the results by month and year as follows:我想創建一個查詢,該查詢給出Sales列的SUM並按月和年對結果進行分組,如下所示:

Apr    2013    3000     Toys
Feb    2013    50000    Bicycle
Jan    2014    4546     Bananas

Is there a simple way to do that?有沒有一種簡單的方法可以做到這一點?


解決方案:

參考一: https://en.stackoom.com/question/1BOVj
參考二: https://stackoom.com/question/1BOVj
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章