Select 包含求和和多行的语句

Select statement with sum and multi-rows

select Document_id, Document_date, sum(document_money)
from documents
group by Docuemnt_id, Docuement_date; 

第一个查询检索到以下结果:

1    01-FEB-2017      10000
2    02-FEB-2017      20000
3    03-FEB-2017      10000

查询#2:

select document_id, Document_date, document_money, document_details
from documents ; 

结果:

1    01-FEB-2017      5000       rentment
1    01-FEB-2017      5000       food
2    02-FEB-2017      10000      car
2    02-FEB-2017      10000      house
3    03-FEB-2017      7000       mobiles
3    03-FEB-2017      3000       drinks

我如何创建一个查询,为我提供 document_no、the_date、 金额及详情如下:

 1    01-FEB-2017      10000      rentment
 1    01-FEB-2017      10000      food
 2    02-FEB-2017      20000      car
 2    02-FEB-2017      20000      house
 3    03-FEB-2017      10000      mobiles
 3    03-FEB-2017      10000      drinks

您需要使用分析 SUM() 函数:

select document_id, document_date, 
       sum(document_money) over (partition by document_id, document_date) as sum_money,
       document_details
from   documents;