Join不支持子查询吗? #591

Closed
opened 2017-05-27 03:20:02 +00:00 by zouhuigang · 5 comments
zouhuigang commented 2017-05-27 03:20:02 +00:00 (Migrated from github.com)

SELECT a.id,a.s_names,a.e_names,b.s_num FROM user_img_cls AS a LEFT JOIN ( SELECT pid,count(id) as s_num FROM user_gif_bg_cls where is_open=1 GROUP BY pid ) AS b ON a.id = b.pid ORDER BY a.is_sort ASC

err = MasterDB.Select("a.id,a.s_names,a.e_names,b.s_num").Table("user_img_cls").Alias("a").
Join("LEFT ", []string{"( SELECT pid,count(id) as s_num FROM user_gif_bg_cls where is_open=1 GROUP BY pid )", "b"}, "a.id = b.pid").
OrderBy("a.is_sort ASC").Find(&list)

SELECT a.id,a.s_names,a.e_names,b.s_num FROM `user_img_cls` AS `a` LEFT JOIN ( SELECT pid,count(id) as s_num FROM user_gif_bg_cls where is_open=1 GROUP BY pid ) AS `b` ON a.id = b.pid ORDER BY a.is_sort ASC err = MasterDB.Select("a.id,a.s_names,a.e_names,b.s_num").Table("user_img_cls").Alias("a"). Join("LEFT ", []string{"( SELECT pid,count(id) as s_num FROM user_gif_bg_cls where is_open=1 GROUP BY pid )", "b"}, "a.id = b.pid"). OrderBy("a.is_sort ASC").Find(&list)

Not supported yet

Not supported yet
zouhuigang commented 2017-05-27 03:31:12 +00:00 (Migrated from github.com)

还有如果使用这样的查询, err = MasterDB.Sql("SELECT a.id,a.s_names,a.e_names,b.s_num FROM user_img_cls a LEFT JOIN ( SELECT pid,count(id) as s_num FROM user_gif_bg_cls where is_open=1 GROUP BY pid) b ON a.id=b.pid where 1=1 ORDER BY is_sort asc ").Find(&list)

count这个函数会被转义掉~~。

还有如果使用这样的查询, err = MasterDB.Sql("SELECT a.id,a.s_names,a.e_names,b.s_num FROM `user_img_cls` a LEFT JOIN ( SELECT pid,count(id) as s_num FROM user_gif_bg_cls where is_open=1 GROUP BY pid) b ON a.id=b.pid where 1=1 ORDER BY is_sort asc ").Find(&list) count这个函数会被转义掉~~。

@zouhuigang the second one is a bug I think. Please fire another issue to describe it.

@zouhuigang the second one is a bug I think. Please fire another issue to describe it.
zouhuigang commented 2017-05-27 03:33:58 +00:00 (Migrated from github.com)

好的,谢谢。

好的,谢谢。

duplicated with #575

duplicated with #575
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#591
No description provided.