我有一个用户名数组作为用户:[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);
}
...

10-07 12:50
查看更多