web2py: 左外连接未返回左侧的所有记录

huangapple go评论72阅读模式
英文:

web2py: left-outer join not giving all records on left

问题

This code is not returning groups with zero (0) count.
(这段代码没有返回计数为零的组。)

英文:

Why is this code not returning groups with zero (0) count? (I am sure there are groups with zero count)

count = db.auth_membership.id.count()
groups = db().select(db.auth_membership.group_id, db.auth_group.role, count, 
    left=db.auth_group.on(db.auth_membership.group_id==db.auth_group.id),
    groupby=db.auth_membership.group_id)

答案1

得分: 0

I finally got it. Here's the query that worked:

query = db.auth_membership.group_id == db.auth_group.id
count = db.auth_membership.id.count()
groups = db(db.auth_group).select(db.auth_group.id, db.auth_group.role, db.auth_membership.id,
    count, 
    groupby=db.auth_group.id,
    left=db.auth_membership.on(query))
英文:

edited

I finally got it. Here's the query that worked:

query = db.auth_membership.group_id == db.auth_group.id
count = db.auth_membership.id.count()
groups = db(db.auth_group).select(db.auth_group.id, db.auth_group.role, db.auth_membership.id,
    count, 
    groupby=db.auth_group.id,
    left=db.auth_membership.on(query))

huangapple
  • 本文由 发表于 2023年3月23日 08:17:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75818298.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定