Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
1560 Näkymät

Hello 

I want to get the amount for a specific employee, here's my function when I print the result I get all the sum of the records. 


def get_sum(self, ):
for rec in self:
rec._cr.execute("SELECT sum(loan_amount) from hr_loan GROUP BY employee_id")
results = rec.env.cr.fetchall()
result = float(''.join(map(str, results[0])))
print("summmmmmmmmmmmm",result)
return result

Avatar
Hylkää
Paras vastaus

Hi,

To fetch the total loan_amount group by employees, you can use the following query:

SELECT SUM(loan_amount)
FROM hr_loan
GROUP BY employee_id;

This will display the results in the following format:

Sum 

4687.50
23963.00
750.00
2145.00
3325.00

If you want to fetch the loan_amount for a specific employee, you can add the employee ID in the WHERE condition like this:

SELECT SUM(loan_amount) 
FROM hr_loan 
WHERE employee_id = 10;

This will display the result like 2145.00.

Regards

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
3
lokak. 23
7270
1
syysk. 23
2549
2
huhtik. 23
1963
1
maalisk. 23
1528
0
maalisk. 23
946