- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 nodejs (express 和 angular) 中做一个项目,我发现这个 sequeelize 有困难。我无法添加不同的(在查询开始时,我收到太多副本)并且我无法为“包含字段”添加订单
我浏览了 Sequielize 文档( http://docs.sequelizejs.com/manual/querying.html#operators-aliases )但没有成功。我在这里找到了一些答案,但仍然没有成功。我究竟做错了什么?
return models.Inspection.findAndCountAll({
distinct: true,
attributes: [],
include: [{model: models.InspectionGroup, attributes:['ID', 'InspectionTypeModel_ID', 'Notes', 'Date'],
required: true, include: [{
model: models.InspectionTypeModel, attributes: ['Model'], required: true
}]},
{model: models.UnitElement, attributes: [], required: true, include: [{
model: models.Span, attributes: [], required: true, include: [{
model: models.StructuralUnit, attributes: [], required: true, include: [{
model: models.Building, attributes: [], required: true, include: [{
model: models.Direction, attributes: [], required: true, include: [{
model: models.Road, attributes: [], where: {Dealer_ID: dealerList}, required: true
}]
}]
}]
}]
}]
}],
order: [[ { model: models.InspectionGroup }, 'Date', 'DESC']],
limit: limit,
offset: offset
})
.then(function (results) {
res.json(results);
})
.catch(function (err) {
commons.showerror(err, res);
});
SELECT [Inspection].[ID], [InspectionGroup].[ID] AS [InspectionGroup.ID], [InspectionGroup].[InspectionTypeModel_ID] AS [InspectionGroup.InspectionTypeModel_ID],
[InspectionGroup].[Notes] AS [InspectionGroup.Notes], [InspectionGroup].[Date] AS [InspectionGroup.Date], [InspectionGroup.InspectionTypeModel].[ID] AS [InspectionGroup.InspectionTypeModel.ID],
[InspectionGroup.InspectionTypeModel].[Model] AS [InspectionGroup.InspectionTypeModel.Model]
FROM [Inspection] AS [Inspection]
INNER JOIN [InspectionGroup] AS [InspectionGroup] ON [Inspection].[InspectionGroup_ID] = [InspectionGroup].[ID]
INNER JOIN [InspectionTypeModel] AS [InspectionGroup.InspectionTypeModel] ON [InspectionGroup].[InspectionTypeModel_ID] = [InspectionGroup.InspectionTypeModel].[ID]
INNER JOIN [UnitElement] AS [UnitElement] ON [Inspection].[UnitElement_ID] = [UnitElement].[ID] INNER JOIN [Span] AS [UnitElement.Span] ON [UnitElement].[Span_ID] = [UnitElement.Span].[ID]
INNER JOIN [StructuralUnit] AS [UnitElement.Span.StructuralUnit] ON [UnitElement.Span].[StructuralUnit_ID] = [UnitElement.Span.StructuralUnit].[ID] INNER JOIN [Building] AS [UnitElement.Span.StructuralUnit.Building] ON [UnitElement.Span.StructuralUnit].[Building_ID] = [UnitElement.Span.StructuralUnit.Building].[ID]
INNER JOIN [Direction] AS [UnitElement.Span.StructuralUnit.Building.Direction] ON [UnitElement.Span.StructuralUnit.Building].[Direction_ID] = [UnitElement.Span.StructuralUnit.Building.Direction].[ID] INNER JOIN [Road] AS [UnitElement.Span.StructuralUnit.Building.Direction.Road] ON [UnitElement.Span.StructuralUnit.Building.Direction].[Road_ID] = [UnitElement.Span.StructuralUnit.Building.Direction.Road].[ID] AND [UnitElement.Span.StructuralUnit.Building.Direction.Road].[Dealer_ID] IN (4, 12)
ORDER BY [InspectionGroup].[Date] DESC ORDER BY [ID] OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY
SELECT [Inspection].[ID], distinct([ID]) AS [inspectionId], [InspectionGroup].[ID] AS [InspectionGroup.ID], [InspectionGroup].[InspectionTypeModel_ID] AS [InspectionGroup.InspectionTypeModel_ID],
[InspectionGroup].[Notes] AS [InspectionGroup.Notes], [InspectionGroup].[Date] AS [InspectionGroup.Date], [InspectionGroup.InspectionTypeModel].[ID] AS [InspectionGroup.InspectionTypeModel.ID],
[InspectionGroup.InspectionTypeModel].[Model] AS [InspectionGroup.InspectionTypeModel.Model]
FROM [Inspection] AS [Inspection]
INNER JOIN [InspectionGroup] AS [InspectionGroup] ON [Inspection]. [InspectionGroup_ID] = [InspectionGroup].[ID]
INNER JOIN [InspectionTypeModel] AS [InspectionGroup.InspectionTypeModel] ON [InspectionGroup].[InspectionTypeModel_ID] = [InspectionGroup.InspectionTypeModel].[ID]
INNER JOIN [UnitElement] AS [UnitElement] ON [Inspection].[UnitElement_ID] = [UnitElement].[ID] INNER JOIN [Span] AS [UnitElement.Span] ON [UnitElement].[Span_ID] = [UnitElement.Span].[ID]
INNER JOIN [StructuralUnit] AS [UnitElement.Span.StructuralUnit] ON [UnitElement.Span].[StructuralUnit_ID] = [UnitElement.Span.StructuralUnit].[ID] INNER JOIN [Building] AS [UnitElement.Span.StructuralUnit.Building] ON [UnitElement.Span.StructuralUnit].[Building_ID] = [UnitElement.Span.StructuralUnit.Building].[ID]
INNER JOIN [Direction] AS [UnitElement.Span.StructuralUnit.Building.Direction] ON [UnitElement.Span.StructuralUnit.Building].[Direction_ID] = [UnitElement.Span.StructuralUnit.Building.Direction].[ID]
INNER JOIN [Road] AS [UnitElement.Span.StructuralUnit.Building.Direction.Road] ON [UnitElement.Span.StructuralUnit.Building.Direction].[Road_ID] = [UnitElement.Span.StructuralUnit.Building.Direction.Road].[ID] AND [UnitElement.Span.StructuralUnit.Building.Direction.Road].[Dealer_ID] IN (4, 12)
ORDER BY [Inspection].[Date] DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY
最佳答案
如果我没有错,您应该在路由模型上至少放置一个属性,以便能够在该列上应用不同的属性。否则,没有列可以应用它。
让我们试试看它是否有效
distinct: true,
attributes: [´id’]
return models.Inspection.findAndCountAll({
attributes: [[ Sequelize.fn('DISTINCT', Sequelize.col('Inspection.ID')), 'Inspection.ID']],
include: [{model: models.InspectionGroup, attributes:['ID', 'InspectionTypeModel_ID', 'Notes', 'Date'],
required: true, include: [{
model: models.InspectionTypeModel, attributes: ['Model'], required: true
}]},
{model: models.UnitElement, attributes: [], required: true, include: [{
model: models.Span, attributes: [], required: true, include: [{
model: models.StructuralUnit, attributes: [], required: true, include: [{
model: models.Building, attributes: [], required: true, include: [{
model: models.Direction, attributes: [], required: true, include: [{
model: models.Road, attributes: [], where: {Dealer_ID: dealerList}, required: true
}]
}]
}]
}]
}]
}],
order: [[ { model: models.InspectionGroup }, 'Date', 'DESC']],
limit: limit,
offset: offset
})
.then(function (results) {
res.json(results);
})
.catch(function (err) {
commons.showerror(err, res);
});
关于sql - 如何在 include 中插入 Distinct 和 Order?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56134493/
我有一个包含电子邮件、IP、州、城市、时间戳、ID 列的表 我需要按州分组计算电子邮件和 IP 的不同位置 所以当我运行 MYSQL 查询时, select State, City ,count(di
我试过 select distinct ID from DB.TABLE; 它返回所有记录中的唯一 ID。 select distinct * from DB.TABLE; 它将通过比较所有列
我正在尝试在 Postgresql 中编写一个查询,该查询提取一组有序数据并按不同的字段对其进行过滤。我还需要从同一表行中提取其他几个字段,但需要将它们排除在不同的评估之外。示例: SELECT
我有一个使用以下语句创建的 Postgres 表。该表由另一个服务的数据转储填充。 CREATE TABLE data_table ( date date DEFAULT NULL,
我在一个名为 products 的表中有 4 列 id|p_name| p_img | 1 | Xs | xsmax.png | 2 | Xs | xr.png |
当它的状态仅为"is"时,我想从“num”中选择不同的值,而不是立即包括“否”? 表: +--------+-----+--------+ | id | num | status | +---
全部!今天我有一个棘手的问题要给你,我想使用 select DISTINCT 语句来选择一个需要不同的行,但也在同一个语句中(或者我尝试过的方式?)一个没有的行't/不能区分。我想要的结果是每个类名中
我有一个正在使用 Distinct() 的 linq 查询。如果我只是调用 Distinct() 而没有转换为列表,那么它不会返回不同的列表 - 它仍然包含重复项。 但是,如果我转换为 List 并然
说到性能,我应该使用 .ToList().Distinct() 还是 .Distinct().ToList() ? 两种扩展方法是否生成相同的 SQL 查询? 看起来第二种方法应该表现更好,但这是真的
如何在不支持 SQL Server 2008R2 的 SQL 实现中重写包含标准 IS DISTINCT FROM 和 IS NOT DISTINCT FROM 运算符的表达式? 最佳答案 IS DI
有一张 table (在 HIVE) 示例 - meanalytics.key2_master_ids 该表有 6 列(cmpgn_id、offr_id、exec_id、creatv_id、cmpl_
SELECT * FROM `amc_info` WHERE department =' ( SELECT DISTINCT department ) into outfile = 'Differe
如何在Elasticsearch中计算“不同的平均值”?我有一些这样的非规范化数据: { "record_id" : "100", "cost" : 42 } { "record_id" : "200
关注这个question我有... ID SKU PRODUCT ======================= 1 FOO-23 Orange 2 BAR
我有这个 mysql 查询: SELECT DISTINCT post.postId,hash,previewUrl,lastRetrieved FROM post INNER JOIN (tag a
http://sqlfiddle.com/#!2/37dd94/17 如果我执行 SELECT DISTINCT,我得到的结果与只执行 SELECT 的结果相同。 在查询结果中,您将看到两个包含 Di
我有一列包含空条目,例如此列中的可能值为 None, 1, 2, 3 当我使用 session.query(func.count(distinct(Entry.col))).scalar() 计算列中
这是否可能从表列中选择不同的行并计算单个查询中每个不同字段的重复行 $sql = "SELECT DISTINCT location and COUNT(DISTINCT location)
我在 MySQL 数据库中有一个包含 1100 万行的表。其中一列是个人身份证号码。人们在表中被多次列出,我想知道有多少个唯一的个人 ID 号码。然后创建一个包含这些唯一数字的表格。当我计算列中不同的
我刚刚注意到我的 Informix SQL 列(在同一个表中)的某些 上有些奇怪。当我执行此查询时 SELECT DISTINCT colName FROM myTable 例如,我得到 40 行。但
我是一名优秀的程序员,十分优秀!