次のクエリのすべてが、正しい情報を含むinvBlueprintTypes行ごとに1行になります。しかし、私はそれに何かを追加しようとしています。以下のコードブロックを参照してください。
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
したがって、ここで取得する必要があるのは、次の表とその下の列です。これにより、値のタイムスタンプを使用して、結果全体をprofitHourで並べ替えることができます。
tablename: invBlueprintTypesPrices
columns: blueprintTypeID, timestamp, profitHour
次の選択を念頭に置いてこの情報が必要です。selectを使用して、JOIN /in-queryselectまたはこれを実行できるものの意図を示します。
SELECT * FROM invBlueprintTypesPrices
WHERE blueprintTypeID = blueprintType.typeID
ORDER BY timestamp DESC LIMIT 1
また、invBlueprintTypesPricesの結果がない場合でも、テーブルinvBlueprintTypesのメイン行を表示する必要があります。LIMIT 1は、可能な限り最新の行が必要なためですが、履歴が必要なため、古いデータを削除することはできません。
正しく理解していれば、サブクエリselectが必要だと思いますが、それを行うにはどうすればよいですか?クエリの終了後にASblueprintPricesを使用して上記の正確なクエリを追加するのに疲れましたが、
WHERE blueprintTypeID = blueprintType.typeID
エラーの焦点となる部分。理由はわかりません。これを解決できる人はいますか?