我有这个代码:
select count(distinct affiliate_orders_id) as count
, sum(affiliate_value) as total
, sum(affiliate_payment) as payment
from " . TABLE_AFFILIATE_SALES . " a
left join " . TABLE_ORDERS . " o on (a.affiliate_orders_id = o.orders_id)
where a.affiliate_orders_id = o.orders_id
and o.orders_status >= " . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . "
";
$affiliate_sales_query= tep_db_query($affiliate_sales_raw);
$affiliate_sales= tep_db_fetch_array($affiliate_sales_query);
因此,$affiliate_sales['total'] = 128000 实际上应该是 32000,因为有多个affiliate_values 和affiliate_orders_id。affilaite_values 一些具有相同的值,因此它们不能不同。affilaite_orders_id 具有所有唯一值,但有多个行并且需要不同。然后,affiliate_values 必须根据affiliate_orders_id 的不同行求和以获得准确的总和。
我正在尝试获取所有affiliate_values 的总和,以确定表中有多少不同的affiliate_orders_id。