以下查询中的所有内容都会为每个具有正确信息的 invBlueprintTypes 行生成一行。但我正在尝试添加一些东西。请参阅下面的代码块。
Select
blueprintType.typeID,
blueprintType.typeName Blueprint,
productType.typeID,
productType.typeName Item,
productType.portionSize,
blueprintType.basePrice * 0.9 As bpoPrice,
productGroup.groupName ItemGroup,
productCategory.categoryName ItemCategory,
blueprints.productionTime,
blueprints.techLevel,
blueprints.researchProductivityTime,
blueprints.researchMaterialTime,
blueprints.researchCopyTime,
blueprints.researchTechTime,
blueprints.productivityModifier,
blueprints.materialModifier,
blueprints.wasteFactor,
blueprints.maxProductionLimit,
blueprints.blueprintTypeID
From
invBlueprintTypes As blueprints
Inner Join invTypes As blueprintType On blueprints.blueprintTypeID = blueprintType.typeID
Inner Join invTypes As productType On blueprints.productTypeID = productType.typeID
Inner Join invGroups As productGroup On productType.groupID = productGroup.groupID
Inner Join invCategories As productCategory On productGroup.categoryID = productCategory.categoryID
Where
blueprints.techLevel = 1 And
blueprintType.published = 1 And
productType.marketGroupID Is Not Null And
blueprintType.basePrice > 0
所以我需要在这里输入下表及其下方的列,以便我可以使用值时间戳并按利润小时对整个结果进行排序
tablename: invBlueprintTypesPrices
columns: blueprintTypeID, timestamp, profitHour
我需要此信息并考虑以下选择。使用选择来显示我对 JOIN/in-query 选择或任何可以做到这一点的意图。
SELECT * FROM invBlueprintTypesPrices
WHERE blueprintTypeID = blueprintType.typeID
ORDER BY timestamp DESC LIMIT 1
即使 invBlueprintTypesPrices 没有结果,我也需要表 invBlueprintTypes 中的主行仍然显示。LIMIT 1 是因为我想要最新的行,但删除旧数据不是一个选项,因为需要历史记录。
如果我理解正确,我认为我需要一个子查询选择,但该怎么做呢?我已经厌倦了在查询关闭后使用 AS blueprintPrices 添加上面的确切查询),但没有出现错误
WHERE blueprintTypeID = blueprintType.typeID
部分是错误的焦点。我不知道为什么。谁能解决这个问题?