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
答案 0 :(得分:1)
您需要使用分析 SUM()函数:
select document_id, document_date,
sum(document_money) over (partition by document_id, document_date) as sum_money,
document_details
from documents;