NutzCN Logo
问答 Sql中有where情况下Cnd问题
发布于 2836天前 作者 qq_cf257b19 2166 次浏览 复制 上一个帖子 下一个帖子
标签:

自定义中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

可以这样写哦

Cnd.where(new Static("gu.member_id != g1.manager")).and("gu.group_id","=",id);

@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

刚才火狐狸突然抽了换chrome换了个账号回了一下

cnd.where是静态方法啊

曲线救国了一下....这么写ok了
cnd.and("gu.member_id != g1.manager and 1","=","1");

添加回复
请先登陆
回到顶部