私は以下のクエリの結果を転置することを検討しています。Magento用のTranspose Mysqlクエリ
SELECT pro_dec.entity_id,
attr.attribute_id,
attr.attribute_code AS attribute_name,
pro_dec.VALUE
FROM `magento_eav_attribute` AS attr
INNER JOIN magento_catalog_product_entity_decimal AS pro_dec
ON pro_dec.attribute_id = attr.attribute_id
WHERE attr.`entity_type_id` = 4
AND attr.`backend_type` = 'decimal'
ORDER BY pro_dec.entity_id
//Output1
entity_id attribute_id attribute_name value
376 60 price 25.0000
376 65 weight 1.0000
377 60 price 35.0000
377 65 weight 3.0000
私は私が私の望ましい結果を与えるかなり長いネストされたSELECTクエリを書かれている次の出力結果
//Output2
entity_id price weight
376 25.0000 1.0000
377 35.0000 3.0000
を達成しようとしています。 Output2のクエリを取得するためのより良い/簡単な方法はありますか?これは価格と重量の2つの属性に対してのみです。
SELECT ent.entity_id,
ent.type_id,
(SELECT pro_dec.VALUE AS VALUE
FROM `magento_eav_attribute` AS attr
INNER JOIN magento_catalog_product_entity_decimal AS pro_dec
ON pro_dec.attribute_id = attr.attribute_id
WHERE attr.`entity_type_id` = 4
AND attr.`backend_type` = 'decimal'
AND attr.attribute_id = 60
AND pro_dec.entity_id = ent.entity_id
ORDER BY pro_dec.entity_id) AS price,
(SELECT pro_dec.VALUE AS VALUE
FROM `magento_eav_attribute` AS attr
INNER JOIN magento_catalog_product_entity_decimal AS pro_dec
ON pro_dec.attribute_id = attr.attribute_id
WHERE attr.`entity_type_id` = 4
AND attr.`backend_type` = 'decimal'
AND attr.attribute_id = 65
AND pro_dec.entity_id = ent.entity_id
ORDER BY pro_dec.entity_id) AS weight
FROM magento_catalog_product_entity AS ent
//編集2 は、ここでも少し肥大化している参加クエリだと、おそらくそのような
SELECT ent.entity_id,
ent.type_id,
price.VALUE AS price,
weight.VALUE AS weight
FROM magento_catalog_product_entity AS ent
INNER JOIN (SELECT pro_dec.entity_id AS entity_id,
attr.attribute_id AS attribute_id,
attr.attribute_code AS attribute_name,
pro_dec.VALUE AS VALUE
FROM `magento_eav_attribute` AS attr
INNER JOIN magento_catalog_product_entity_decimal AS
pro_dec
ON pro_dec.attribute_id = attr.attribute_id
WHERE attr.`entity_type_id` = 4
AND attr.`backend_type` = 'decimal'
AND attr.attribute_id = 60
ORDER BY pro_dec.entity_id) AS price
ON price.entity_id = ent.entity_id
INNER JOIN (SELECT pro_dec.entity_id AS entity_id,
attr.attribute_id AS attribute_id,
attr.attribute_code AS attribute_name,
pro_dec.VALUE AS VALUE
FROM `magento_eav_attribute` AS attr
INNER JOIN magento_catalog_product_entity_decimal AS
pro_dec
ON pro_dec.attribute_id = attr.attribute_id
WHERE attr.`entity_type_id` = 4
AND attr.`backend_type` = 'decimal'
AND attr.attribute_id = 65
ORDER BY pro_dec.entity_id) AS weight
ON weight.entity_id = ent.entity_id
WHERE ent.type_id = 'configurable'
ネストしたクエリを投稿して、最適化できるかどうかを確認してください。基本的には、レポートのために独自のネストされたクエリーを書くことが最善の方法です。アプリケーション(ビジネスロジックなど)でデータを使用している場合は、Magento ORM(Zend DB)を使用して後で結果をソートする必要があります。 –
質問に私の質問を追加しました。 – rdsoze
最初はRubyでMagento Core Apiを使用しようとしましたが、APIコールは遅すぎました。私はxmlrpc/soapコールを作るためのsavonとmagentorの宝石にも問題がありました。だから私は質問レベルに下がることを考えた。 – rdsoze