using sql in jinja is litil difficult i think but you can try this way
if your Risk Profile doc is custom doc then you can call direct python script
write method in class
eg
class RiskProfile():
def get_data()
//you code
and call that method in jinja directly
{{doc.get_data()}}