我创建了以下查询,除了应该显示颜色和大小的sopa.products_options外,它的工作非常棒。但是,我从db返回一个整数值(34和9而不是3XL和Lilac)。它可以在我的本地机器上运行,但不能通过在PHP版本5.0.91上运行的phpmyadmin。
这是我的问题:
SELECT
o.orders_id
, o.customers_id
, o.customers_name
, o.customers_company
, o.customers_street_address
, o.customers_suburb
, o.customers_city
, o.customers_postcode
, o.customers_state
, o.customers_country
, o.customers_telephone
, o.customers_email_address
, o.delivery_name
, o.delivery_company
, o.delivery_street_address
, o.delivery_suburb
, o.delivery_city
, o.delivery_postcode
, o.delivery_state
, o.delivery_country
, o.billing_name
, o.billing_company
, o.billing_street_address
, o.billing_suburb
, o.billing_city
, o.billing_postcode
, o.billing_state
, o.billing_country
, o.payment_method
, o.last_modified
, o.date_purchased
, o.orders_status
, os.orders_status_name
, o.orders_date_finished
, o.currency AS orders_currency
, o.currency_value AS orders_currency_value
, (
SELECT
SUM(ot.value)
FROM
orders_total AS ot
WHERE
ot.orders_id = o.orders_id
AND ot.class = 'ot_shipping'
) AS orders_shipping
, (
SELECT
SUM(ot.value)
FROM
orders_total AS ot
WHERE
ot.orders_id = o.orders_id
AND ot.class = 'ot_subtotal'
) AS orders_subtotal
, (
SELECT
SUM(ot.value)
FROM
orders_total AS ot
WHERE
ot.orders_id = o.orders_id
AND ot.class = 'ot_total'
) AS orders_total
, op.products_id
, op.products_model
, op.products_name
, op.products_quantity
, op.products_price
, op.final_price AS products_final_price
, (
SELECT
SUM(sopa.options_values_price)
FROM
orders_products_attributes AS sopa
WHERE
sopa.orders_id = o.orders_id
AND sopa.products_options = 'Color'
) AS products_color_option
, (
SELECT
SUM(sopa.options_values_price)
FROM
orders_products_attributes AS sopa
WHERE
sopa.orders_id = o.orders_id
AND sopa.products_options = 'Size'
) AS products_size_option
FROM
orders AS o
INNER JOIN orders_products AS op
ON o.orders_id = op.orders_id
INNER JOIN orders_status AS os
ON o.orders_status = os.orders_status_id
;
有什么想法吗?
非常感谢! 克里斯
编辑:这是我的SOPA表格结构
--
-- Table structure for table `orders_products_attributes`
--
CREATE TABLE `orders_products_attributes` (
`orders_products_attributes_id` int(11) NOT NULL auto_increment,
`orders_id` int(11) NOT NULL,
`orders_products_id` int(11) NOT NULL,
`products_options` varchar(32) NOT NULL,
`products_options_values` varchar(32) NOT NULL,
`options_values_price` decimal(15,4) NOT NULL,
`price_prefix` char(1) NOT NULL,
`options_values_weight` decimal(6,3) NOT NULL default '0.000',
`weight_prefix` char(1) NOT NULL,
`products_options_id` int(11) NOT NULL default '0',
`products_options_values_id` int(11) NOT NULL default '0',
PRIMARY KEY (`orders_products_attributes_id`),
KEY `idx_orders_products_att_orders_id` (`orders_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;
--
-- Dumping data for table `orders_products_attributes`
--
INSERT INTO `orders_products_attributes` VALUES(1, 1, 1, 'Size', '3X-Large', 8.0000, '+', 0.000, '', 1, 9);
INSERT INTO `orders_products_attributes` VALUES(2, 1, 1, 'Color', 'Lilac', 0.0000, '', 0.000, '', 2, 17);
INSERT INTO `orders_products_attributes` VALUES(3, 1, 2, 'Size', 'Medium', 0.0000, '', 0.000, '', 1, 5);
INSERT INTO `orders_products_attributes` VALUES(4, 1, 2, 'Color', 'White', 0.0000, '', 0.000, '', 2, 29);
INSERT INTO `orders_products_attributes` VALUES(5, 1, 3, 'Size', '4X-Large', 10.0000, '+', 0.000, '', 1, 10);
INSERT INTO `orders_products_attributes` VALUES(6, 1, 3, 'Color', 'Lilac', 0.0000, '', 0.000, '', 2, 17);
INSERT INTO `orders_products_attributes` VALUES(7, 1, 4, 'Color', 'Lilac', 0.0000, '', 0.000, '', 2, 17);
INSERT INTO `orders_products_attributes` VALUES(8, 1, 4, 'Size', '4X-Large', 10.0000, '+', 0.000, '', 1, 10);
INSERT INTO `orders_products_attributes` VALUES(9, 1, 5, 'Size', '3X-Large', 6.0000, '+', 0.000, '', 1, 9);
INSERT INTO `orders_products_attributes` VALUES(10, 1, 5, 'Color', 'Blue', 0.0000, '', 0.000, '', 2, 14);
INSERT INTO `orders_products_attributes` VALUES(11, 1, 6, 'Size', '3X-Large', 0.0000, '', 0.000, '', 1, 9);
INSERT INTO `orders_products_attributes` VALUES(12, 1, 6, 'Color', 'White', 0.0000, '', 0.000, '', 2, 29);
INSERT INTO `orders_products_attributes` VALUES(13, 2, 7, 'Size', '2X-Large', 4.0000, '+', 0.000, '', 1, 8);
INSERT INTO `orders_products_attributes` VALUES(14, 2, 7, 'Color', 'Yellow', 0.0000, '', 0.000, '', 2, 15);
INSERT INTO `orders_products_attributes` VALUES(15, 2, 8, 'Size', 'Large', 5.0000, '+', 0.000, '', 1, 6);
INSERT INTO `orders_products_attributes` VALUES(16, 2, 8, 'Color', 'Clear', 0.0000, '', 0.000, '', 2, 12);
INSERT INTO `orders_products_attributes` VALUES(17, 2, 9, 'Size', '2X-Large', 0.0000, '', 0.000, '', 1, 8);
INSERT INTO `orders_products_attributes` VALUES(18, 2, 9, 'Color', 'Blue', 0.0000, '', 0.000, '', 2, 14);