| fkStockItemId | PropertyName | PropertyValue | PropertyType |
| ItemSKU-1 | Item Style | SB-01123 | Attribute |
| ItemSKU-1 | Item Size | X-Small | Attribute |
| ItemSKU-1 | Item Color | Red | Attribute |
| ItemSKU-2 | Item Style | AA-66002 | Attribute |
| ItemSKU-2 | Item Size | Medium | Attribute |
| ItemSKU-2 | Item Color | Green | Attribute |
| ItemSKU-3 | Item Style | 110445 | Attribute |
| ItemSKU-3 | Item Size | Small | Attribute |
我试图得到的输出是这样的:
| SKU | Item Style | Item Size | Item Color |
| ItemSKU-1 | SB-01123 | X-Small | Red |
| ItemSKU-2 | AA-66002 | Medium | Green |
| ItemSKU-3 | 110445 | Small | *Null* |
Please note that last column "PropertyType" is for technical purposes and
is not needed to be queried.
这是我到目前为止得到的:
SELECT si.ItemNumber, si.ItemTitle, si.ItemDescription, si.RetailPrice, si.Weight, sl.Quantity, c.CategoryName, siep.ProperyValue, siep.ProperyName
FROM StockItem si
LEFT OUTER JOIN StockLevel sl ON si.pkStockItemID = sl.fkStockItemId
LEFT OUTER JOIN ProductCategories c ON si.CategoryId = c.CategoryId
LEFT OUTER JOIN StockItem_ExtendedProperties siep ON si.pkStockItemID = siep.fkStockItemId
WHERE siep.ProperyName = 'Item Style'
表“StockLevel”和“ProductCategories”显示结果很好。如果您注意到,最后“StockItem_ExtendedProperties”JOIN 和“siep.ProperyValue”、“siep.ProperyName”加上“WHERE siep.ProperyName = 'Item Style'”只允许我查询 1 个属性。感谢您的帮助和时间!