아래에서 언급 한 결과를 제공하는 다음 쿼리의 결과를 조 변경하려고합니다. 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
나는 다음과 같은 출력 결과 나는 나에게 원하는 결과를 제공하는 다소 긴 중첩 된 선택 쿼리를 작성했습니다
//Output2
entity_id price weight
376 25.0000 1.0000
377 35.0000 3.0000
를 달성하기 위해 노력하고 있습니다. Output2에 대한 쿼리를 얻는 더 좋고/더 쉬운 방법이 있습니까?
// 편집 1 여기에 작성한 중첩 쿼리가 있습니다. 이것은 가격과 무게라는 두 가지 속성에만 해당됩니다.
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
처음에 Magento Core Api를 루비와 함께 사용하려고했지만 API 호출이 너무 느립니다. 나는 또한 xmlrpc/soap 전화를 만들기 위해 savon과 magentor 보석에 문제가있었습니다. 그래서 나는 쿼리 수준으로 내려가는 것을 생각했다. – rdsoze