使用builder生成的 JOIN 连表查询语句用xorm进行查询,查询的字段与实际的字段不一样 #1747

Open
opened 1 year ago by conero · 3 comments
conero commented 1 year ago

连表查询示例

vsqlMk := builder.Select("cur.id", "u.name", "m.name member", "cur.status", "cur.is_admin", "cur.ctime",
			"cu.name cname").
			From("clan_user_ref", "cur").
			InnerJoin("clan c", "cur.clan_id = c.id").
			InnerJoin("user u", "cur.user_id = u.id").
			InnerJoin("user cu", "cur.cuid = cu.id").
			LeftJoin("clan_member m", "cur.member_id = m.id").
			Where(builder.Eq{"cur.del_mk": 0, "cur.clan_id": clanId}).
			OrderBy("cur.ctime desc")


//方式1
sqlAndBinds := []interface{}{vSql}
sqlAndBinds = append(sqlAndBinds, args...)
data, er = db.QueryInterface(sqlAndBinds...)

//方式2
//er = db.SQL(vSql, args...).Find(&data)

两者查询的结果相同,但是与实际的sql执行完全不同
image

image

**连表查询示例** ```go vsqlMk := builder.Select("cur.id", "u.name", "m.name member", "cur.status", "cur.is_admin", "cur.ctime", "cu.name cname"). From("clan_user_ref", "cur"). InnerJoin("clan c", "cur.clan_id = c.id"). InnerJoin("user u", "cur.user_id = u.id"). InnerJoin("user cu", "cur.cuid = cu.id"). LeftJoin("clan_member m", "cur.member_id = m.id"). Where(builder.Eq{"cur.del_mk": 0, "cur.clan_id": clanId}). OrderBy("cur.ctime desc") //方式1 sqlAndBinds := []interface{}{vSql} sqlAndBinds = append(sqlAndBinds, args...) data, er = db.QueryInterface(sqlAndBinds...) //方式2 //er = db.SQL(vSql, args...).Find(&data) ``` *两者查询的结果相同,但是与实际的sql执行完全不同* ![image](/attachments/b7b432c8-d42f-46a2-b16e-bc31b4ad1d44) ![image](/attachments/71abd54b-fdb5-4051-ae1e-10c929689e30)
Owner

时间的SQL是指什么?

时间的SQL是指什么?
Poster

@betacat0 十分抱歉,内容写错了。我指的是:builder执行的sql结果内容与用于查询分析器等工具执行的结果内容不一样

@betacat0 十分抱歉,内容写错了。我指的是:builder执行的sql结果内容与用于查询分析器等工具执行的结果内容不一样
Owner

Is the generated SQL right?

Is the generated SQL right?
lunny added the
need/feedback
label 6 months ago
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.