自定义中sql以where结尾 比如 select * from a left Join b on a.id=b.id where a.name!=b.name
再加cnd.and报错
cnd在sql后面自动拼接了一个where。如果把与sql中的where 加到cnd中 cnd自动把b.name变成了‘b.name’参数格式
请问应该如何解决这种问题
7 回复
自定义sql
SELECT
manager AS a_manager,
member_id AS b_user_id,
group_id AS a_id,
NAME AS a_name,
create_date AS a_create_date,
su1.nickname AS c_nickname,
su.nickname AS d_nickname
FROM
(
SELECT
g.manager member_id,
g.id group_id
FROM
edu_teaching_group g
UNION
SELECT
gm.user_id member_id,
gm.group_id group_id
FROM
edu_teaching_group_member gm
) gu
LEFT JOIN sys_user su ON gu.member_id = su.id
LEFT JOIN edu_teaching_group g1 ON gu.group_id = g1.id
LEFT JOIN sys_user su1 ON g1.manager = su1.id
WHERE
gu.member_id != g1.manager
加cnd
@At("/teachingGroup")
@Ok("json:full")
@RequiresAuthentication
public Object teachingGroup(@Param("id") String id,@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns){
Cnd cnd=Cnd.NEW();
if (!Strings.isBlank(id))
cnd.and("gu.group_id","=",id);
return eduTeacherService.group(length, start, draw, order, columns, cnd, null);
}
最终执行的sql是这个:SELECT manager AS a_manager, member_id AS b_user_id, group_id AS a_id, NAME AS a_name, create_date AS a_create_date, su1.nickname AS c_nickname, su.nickname AS d_nickname FROM ( SELECT g.manager member_id, g.id group_id FROM edu_teaching_group g UNION SELECT gm.user_id member_id, gm.group_id group_id FROM edu_teaching_group_member gm ) gu LEFT JOIN sys_user su ON gu.member_id = su.id LEFT JOIN edu_teaching_group g1 ON gu.group_id = g1.id LEFT JOIN sys_user su1 ON g1.manager = su1.id WHERE gu.member_id != g1.manager WHERE gu.group_id=? LIMIT 0, 20
@At("/teachingGroup")
@Ok("json:full")
@RequiresAuthentication
public Object teachingGroup(@Param("id") String id,@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns){
Cnd cnd=Cnd.NEW();
cnd.where(new Static("gu.member_id != g1.manager"));
if (!Strings.isBlank(id))
cnd.and("gu.group_id","=",id);
return eduTeacherService.group(length, start, draw, order, columns, cnd, null);
}
执行sql如下 为什么where并没有被加进去
SELECT manager AS a_manager, member_id AS b_user_id, group_id AS a_id, NAME AS a_name, create_date AS a_create_date, su1.nickname AS c_nickname, su.nickname AS d_nickname FROM ( SELECT g.manager member_id, g.id group_id FROM edu_teaching_group g UNION SELECT gm.user_id member_id, gm.group_id group_id FROM edu_teaching_group_member gm ) gu LEFT JOIN sys_user su ON gu.member_id = su.id LEFT JOIN edu_teaching_group g1 ON gu.group_id = g1.id LEFT JOIN sys_user su1 ON g1.manager = su1.id LIMIT 0, 20
添加回复
请先登陆