1
我試圖做的type_money如何獲得最後一個值並在sql中求和一組值?
|policies|
|id| |policy_num| |type_money|
1 1234 1
2 5678 1
3 3444 2
4 4577 2
|insurances|
|id| |policy_id| |net_insurance|
1 1 100
2 1 200
3 1 400
4 2 500
5 2 600
6 3 100
7 4 200
在這裏,我試圖讓最後一個值
semi result bedore to do the sum
|policy_num| |type_money| |last_net_insurance|
1234 1 400
5678 1 600
3444 2 100
4577 2 200
獲得最後一個值後得到的每個政策和總和net_insurance的最後一個值我想type_money總結這就是我真正需要的
|type money| |sum|
1 1000
2 300
我試過,但我不知道如何讓每一個政策的最後net_insurance也做總和
select * from policies
inner join insurances ON (insurances.policy_id =policies.id)
group by policies.id
這裏就是我這樣做
http://sqlfiddle.com/#!2/acd8e/3
請有人能幫助我的頁面?
我會很感激幫助
意想不到的幫助絕對+1!這就是我需要的先生:)你是如此的偉大。非常感謝你,謝謝我嘗試了小提琴,因爲更好地展示我在做什麼 –
絕對地,它讓事情變得更容易^^^ –