我需要Magento中的「有」SQL函數。據我所知,沒有功能。在Magento中實現具有()的SQL函數
所以我嘗試實現它在集合類
public function addAttributeHaving($attribute)
{
$this->getSelect()->having($attribute);
return $this;
}
,當我使用此功能
$collectionHotel->addAttributeToSort($order, $dir)
->addAttributeHaving('MIN(`apptha_booking_room_types`.`room_price_per_night`) >= '.$lowestprice)
->addAttributeHaving('MIN(`apptha_booking_room_types`.`room_price_per_night`) <= '.$highestprice);
輸出查詢是罰款:
SELECT
`e` . *,
MIN(`apptha_booking_room_types`.room_price_per_night) AS `lowestprice`,
IF(at_status.value_id > 0,
at_status.value,
at_status_default.value) AS `status`,
IF(at_apptha_hotel_period_to.value_id > 0,
at_apptha_hotel_period_to.value,
at_apptha_hotel_period_to_default.value) AS `apptha_hotel_period_to`,
`price_index`.`price`,
`price_index`.`tax_class_id`,
`price_index`.`final_price`,
IF(price_index.tier_price IS NOT NULL,
LEAST(price_index.min_price,
price_index.tier_price),
price_index.min_price) AS `minimal_price`,
`price_index`.`min_price`,
`price_index`.`max_price`,
`price_index`.`tier_price`
FROM
`catalog_product_entity` AS `e`
LEFT JOIN
`apptha_booking_room_types` ON (apptha_booking_room_types.entity_id = e.entity_id)
INNER JOIN
`catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`entity_id` = `e`.`entity_id`)
AND (`at_status_default`.`attribute_id` = '89')
AND `at_status_default`.`store_id` = 0
LEFT JOIN
`catalog_product_entity_int` AS `at_status` ON (`at_status`.`entity_id` = `e`.`entity_id`)
AND (`at_status`.`attribute_id` = '89')
AND (`at_status`.`store_id` = 1)
INNER JOIN
`catalog_product_entity_datetime` AS `at_apptha_hotel_period_to_default` ON (`at_apptha_hotel_period_to_default`.`entity_id` = `e`.`entity_id`)
AND (`at_apptha_hotel_period_to_default`.`attribute_id` = '168')
AND `at_apptha_hotel_period_to_default`.`store_id` = 0
LEFT JOIN
`catalog_product_entity_datetime` AS `at_apptha_hotel_period_to` ON (`at_apptha_hotel_period_to`.`entity_id` = `e`.`entity_id`)
AND (`at_apptha_hotel_period_to`.`attribute_id` = '168')
AND (`at_apptha_hotel_period_to`.`store_id` = 1)
INNER JOIN
`catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id
AND price_index.website_id = '1'
AND price_index.customer_group_id = 0
WHERE
(`e`.`type_id` = 'hotel')
AND (IF(at_status.value_id > 0,
at_status.value,
at_status_default.value) = '1')
AND (IF(at_apptha_hotel_period_to.value_id > 0,
at_apptha_hotel_period_to.value,
at_apptha_hotel_period_to_default.value) >= '2012-11-09')
GROUP BY `e`.`entity_id`
HAVING (MIN(`apptha_booking_room_types`.`room_price_per_night`) >= 0)
AND (MIN(`apptha_booking_room_types`.`room_price_per_night`) <= 999999999)
ORDER BY `lowestprice` asc
當我執行此查詢在MySQL中,輸出很好。
但是當我嘗試使用
$collectionHotel->load();
這個錯誤顯示出來:
SQLSTATE [42S22]:未找到列:1054未知列 「apptha_booking_room_types.room_price_per_night「having子句中'
我盡我所能,但我還是無法解決這個問題。誰能幫忙?
另外,是否有更好的方法來實現having()函數?
你好..三江源答案.. 我已經改變的查詢分成 HAVING('lowestprice'> = 0)AND('lowestprice' <= 999999999) 輸出是在MySQL 但在Magento良好錯誤是相同的 SQLSTATE [42S22]:未找到列:1054'having clause'中的未知列'lowestprice' – sayasemut
它現在產品是什麼SQL? –
輸出sql是好的,nothings錯誤..當我嘗試在mysql中執行輸出,它的工作原理.. – sayasemut