select (select name from company_salesdivision where id=(select division_id from company_company where '{t.company_id}'=id limit 1),
(select username,lastname from company_user where {t.user_id}=id limit 1),
points from company_bonuspoints where {t.company_id}=id
"""
cur.execute(s)
r=cur.fetchone()
a=r[3]+t.points
data['data'].append([r[0]
,r[1],r[2],t.points,t.amount,t.tm,r[3],a,remark
])
ancestor_id=19318
company_id=19318
s=f"""
SELECT COALESCE(d.name,'未划分'),b.name,c.username,a.points::TEXT,a.amount::TEXT,to_char(a.tm,'yyyy-mm-dd HH24:MI:SS')tm,e.points::TEXT,f.amounts::TEXT from (
SELECT * FROM logistics.company_pointsredeemed WHERE ancestor_id = {ancestor_id} {sWhere})A
left outer join (select id ,division_id,name from company_company WHERE ancestor_id = {ancestor_id} )b on b.id = a.company_id
left outer join (SELECT id ,username ,last_name from company_user WHERE ancestor_id = {ancestor_id})c on c.id =a.user_id
left outer join (SELECT id ,name from company_salesdivision )d on d.id =b.id
left outer join (SELECT points,company_id from company_bonuspoints WHERE ancestor_id = {ancestor_id})e on e.company_id =a.company_id
left outer join (SELECT sum(amount)amounts,company_id from company_pointsredeemed WHERE ancestor_id = {ancestor_id} GROUP BY company_id)f on f.company_id=a.company_id