Frappe.db.sql how its work?!

Hi All ,
happy new year

I don’t know why sometimes frappe.db.sql work and others not work

balance = frappe.db.sql(""“select sum(credit)-sum(debit) from tabGL Entry where party = %s”"", doc.customer)

when I run sql query in mariaDB it’s work 100% !

also I do copy past an do some changes fields, tables not work correctly but it’s work in mariaDB

best regards,
thanks

Hi.
What do you mean by not working. Does it return no results or it returns an error? If it’s an error, what is the error?

can you try?
balance = frappe.db.sql(""“select sum(credit) - sum(debit) from tabGL Entry where party = ‘{0}’”"".format(doc.customer))

Edit:
I tried your code, it works fine.

its work when I add. [0][0] at the end of frappe.db.sql

thanks @tundebabzy @magic-overflow ,