我有一个用户名数组:[Test1,Test2]。我必须循环遍历这个数组,并且应该从表 b 中找到不匹配的用户名。我编写了如下查询:
def usersArray = []
def find
params.users.each{
find= sql.rows("select distinct name from table a,table b where a.id=b.id and b.name!=:n",[n:it])
if(find.size >0)
{
def usList = ["nm":find]
usersArray.push(usList);
}
}
从结果中的上述解决方案中,我看到测试 1 和测试 2,即使它们匹配。我应该如何更改查询以仅显示不匹配的用户?
最佳答案
另一种方法 - 计算与参数名称匹配的现有行,然后推送那些为零的行(请原谅错误的语法):
....
numberFound = sql.rows("select count(*)from table a where a.name=:n",[n:it])
if(numberFound = 0)
{
def usList = ["nm":find]
usersArray.push(usList);
}
...
关于mysql - 从表中查找不匹配的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54371965/