Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 博士后按月选择总和_Postgresql_Select - Fatal编程技术网

Postgresql 博士后按月选择总和

Postgresql 博士后按月选择总和,postgresql,select,Postgresql,Select,我有证据: id id_customer id_service amount date 1 1 1 50.0 2018-01-10 2 2 1 15.7 2018-01-18 3 3 2 14.9 2018-02-

我有证据:

id      id_customer     id_service     amount       date 
1           1                1          50.0        2018-01-10
2           2                1          15.7        2018-01-18
3           3                2          14.9        2018-02-07
4           1                3          700.0       2018-02-28
5           2                1          250.0       2018-03-19
6           3                2          315.7       2018-03-08
7           1                1          100.0       2018-04-28
8           2                2          132.0       2018-04-26
我想按2018年的月份进行汇总,并得出如下结果:

  amount  month
    65.7     1
    714.9    2
    565.7    3
    232.0    4
这是我的选择,我需要帮助

select sum(amount),extract(month from date) from evidence where extract(year from date)=2018 and amount>0 group by date;
像这样

SELECT SUM(amount) AS amount , date_trunc('month', date) as month
FROM evidence 
WHERE extract(year from date)=2018
GROUP BY month
按摘录分组(从日期算起的月份)
否则,您将按实际日期分组,这将为每个源记录提供一个组。您希望按每月分组,而不是按日期分组。