简体   繁体   中英

How two join multiple tables with multiple conditions in sqlalchemy

select d.field_value as name,a.mobile,c.balance,a.created_at from users as a inner join user_profiles as b on a.id = b.user_id
inner join wallets as c on c.user_profile_id = b.id
left join profile_details as d on d.user_id = a.id where d.field_name = "name" and c.balance > 0 order by a.id desc;

This is my query and i need to write in sqlalchemy, i have model with all mentioned tables and proper columns. Thanks for yours all efforts and time spent here.

It's pretty easy. I've some links to be referred.

You can refer to the documentation here .

How to join multiple tables here .

How to select only few columns from the query here .

Left and/or right outer join using sqlalchemy here

I think now you may be able to solve your problem. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM