Inline expressions in HQL
What is the most effectiv开发者_如何学Pythone way to write this sql query in HQL
select uar.*, (a.default_user_asset_role_id is not null) as is_default from User_asset_role uar
left outer join account a on a.default_user_asset_role_id = uar.id
where uar.account_id = 3
example results
1 role_read Role Read TRUE
2 role_admin Role Admin FALSE
3 role_write Role Write FALSE
You can use HQL's CASE expression:
select uar.*, CASE WHEN a.default_user_asset_role_id is null THEN 0 ELSE 1 END as is_default from User_asset_role uar
left outer join account a on a.default_user_asset_role_id = uar.id
where uar.account_id = 3
精彩评论