1

你好我尝试在lovefield中使用innerjoin并尝试groupBy像这样使用:

    var userCompanies = '', company = '';
                user = db.getSchema().table('user');
                userCompanies = db.getSchema().table('userCompanies');
                company = db.getSchema().table('company');
                db.select().
                from(user).
                innerJoin(userCompanies, userCompanies.UserId.eq(user.Id)).
                innerJoin(company, company.Id.eq(userCompanies.CompanyId)).
                where(userCompanies.UserId.eq(row["Id"])).exec()
                // groupBy(user, user.Id).exec()
                .then(function(results) {
                  results.forEach(function(row) {
                    console.log(row['user']);
                  });
                })

但它只给我这个错误: Syntax error: (525) Invalid projection list or groupBy columns.

4

1 回答 1

1

userCompanies.Id 和 company.Id 应该出现在 groupBy() 语句中,或者应该是聚合列

例如

  var userCompanies = '',
                company = '';
            user = db.getSchema().table('user');
            userCompanies = db.getSchema().table('userCompanies');
            company = db.getSchema().table('company');
            db.select().
            from(user).
            innerJoin(userCompanies, userCompanies.UserId.eq(user.Id)).
            innerJoin(company, company.Id.eq(userCompanies.CompanyId)).
            where(userCompanies.UserId.eq(row["Id"])).exec()
            groupBy(user.Id).
            groupBy(userCompanies.Id).
            groupBy(company.Id).exec()
                .then(function(results) {
                    results.forEach(function(row) {
                        console.log(row['user']);
                    });
                })
于 2017-01-07T17:47:00.443 回答