Replies: 1 comment
-
Hi @kokizzu, take a look at self join, with statement and sub query. a := CTE("a")
// export columns from 'a' cte
aX := A.X.From(a)
aY := A.Y.From(a)
aZcount := IntegerColumn("zcount").From(a)
sender := Users.AS("sender")
spouse := Users.AS("spouse")
stmt := WITH(
a.AS(
SELECT(
A.X,
A.Y,
COUNT(A.Z).AS("zcount"),
).FROM(
A,
).GROUP_BY(
A.X,
A.Y,
),
),
)(
SELECT(
ax.AS("x"),
sender.Name.AS("sender_name"),
spouse.Name.AS("spouse_name"),
COUNT(aY).AS("count_ay"),
MAX(aZcount).AS("max_az_count"),
).FROM(
a.LEFT_JOIN(sender, aX.EQ(sender.ID)).
LEFT_JOIN(spouse, sender.SpouseID.EQ(spouse.ID)),
).GROUP_BY(
ax,
sender.Name,
spouse.Name,
),
)
var dest []struct {
X string
SenderName string
SpouseName string
CountAY int
MaxAZCount int
}
err := stmt.Query(db, &dest) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem? Please describe.
for example query:
Describe the solution you'd like
Beta Was this translation helpful? Give feedback.
All reactions