我有以下续集功能:
console.log(arr[index + 1], period, type, line, cell, site)
return db.History.findAll({
where: {
createdAt: {
$lt: arr[index + 1],
$gt: period
},
type: type,
'$Line.name$': line
},
attributes: [[sequelize.fn('AVG', sequelize.col('value')), 'value']],
include: [{
model: db.Line,
include: [{
model: db.Cell,
where: { name: cell },
include: [{
model: db.Site,
where: { name: site }
}]
}]
}]
在我的Chai Unit测试中,这个db查询按预期执行并返回正确的值,这里是注销值的示例:
moment("2017-03-02T07:00:00.000") moment("2017-03-02T06:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T08:00:00.000") moment("2017-03-02T07:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T09:00:00.000") moment("2017-03-02T08:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T10:00:00.000") moment("2017-03-02T09:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T11:00:00.000") moment("2017-03-02T10:00:00.000") 'oee' '602' 'Powders' 'Ashford'
moment("2017-03-02T12:00:00.000") moment("2017-03-02T11:00:00.000") 'oee' '602' 'Powders' 'Ashford'
然而,当我在"现实生活中测试这个时,",我收到错误:
RequestError:Column' Histories.id'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
这些是登出的查询示例:
[1] moment("2017-06-01T01:00:00.000") moment("2017-06-01T00:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T02:00:00.000") moment("2017-06-01T01:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T03:00:00.000") moment("2017-06-01T02:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T04:00:00.000") moment("2017-06-01T03:00:00.000") 'oee' '604' 'powders' 'Ashford'
[1] moment("2017-06-01T05:00:00.000") moment("2017-06-01T04:00:00.000") 'oee' '604' 'powders'
我无法看到单元测试中使用的参数与实际使用中的参数之间的差异。我的单元测试使用sqllite
db,而现实生活中使用mssql
,除此之外,我看不出任何差异。
是什么导致了这个?