只显示一个客户
show one custommer only
我想计算一个客户订购产品的总和
我该怎么做?
我有以下代码
$result = mysql_query ("SELECT order_item_name, SUM(product_quantity) FROM wntl_virtuemart_order_items WHERE wntl_virtuemart_order_items.order_item_sku BETWEEN 2 and 2.9 AND order_status= 'U' GROUP BY order_item_sku");
while($row=mysql_fetch_array($result)) {
echo "<tr>";
echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";
echo "<td align='center' width='200'>" . $row['SUM(product_quantity)'] . "</td>";
echo "</tr>";
}
使用这段代码我得到了总计
我想查看一位顾客的总数
thx 提前 grtz
如果您想按客户计数,则需要在 WHERE
条件中指定客户 ID。
例如如果客户 ID 出现在 wntl_virtuemart_order_items
table 中,那么您的查询将如下所示:
SELECT order_item_name, SUM(product_quantity)
FROM wntl_virtuemart_order_items
WHERE wntl_virtuemart_order_items.order_item_sku BETWEEN 2 and 2.9 AND order_status= 'U' AND customer_id = ?
GROUP BY order_item_sku
如果客户 ID 存在于另一个 table 中,那么您将需要使用 JOIN
两个 table,如下例所示:
SELECT order_item_name, SUM(product_quantity)
FROM wntl_virtuemart_order_items JOIN wntl_virtuemart_orders ON wntl_virtuemart_order_items.virtuemart_order_id = wntl_virtuemart_orders.virtuemart_order_id
WHERE wntl_virtuemart_order_items.order_item_sku BETWEEN 2 and 2.9 AND wntl_virtuemart_order_items.order_status= 'U' AND wntl_virtuemart_orders.customer_number = ?
GROUP BY order_item_sku
我想计算一个客户订购产品的总和 我该怎么做?
我有以下代码
$result = mysql_query ("SELECT order_item_name, SUM(product_quantity) FROM wntl_virtuemart_order_items WHERE wntl_virtuemart_order_items.order_item_sku BETWEEN 2 and 2.9 AND order_status= 'U' GROUP BY order_item_sku");
while($row=mysql_fetch_array($result)) {
echo "<tr>";
echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";
echo "<td align='center' width='200'>" . $row['SUM(product_quantity)'] . "</td>";
echo "</tr>";
}
使用这段代码我得到了总计 我想查看一位顾客的总数
thx 提前 grtz
如果您想按客户计数,则需要在 WHERE
条件中指定客户 ID。
例如如果客户 ID 出现在 wntl_virtuemart_order_items
table 中,那么您的查询将如下所示:
SELECT order_item_name, SUM(product_quantity)
FROM wntl_virtuemart_order_items
WHERE wntl_virtuemart_order_items.order_item_sku BETWEEN 2 and 2.9 AND order_status= 'U' AND customer_id = ?
GROUP BY order_item_sku
如果客户 ID 存在于另一个 table 中,那么您将需要使用 JOIN
两个 table,如下例所示:
SELECT order_item_name, SUM(product_quantity)
FROM wntl_virtuemart_order_items JOIN wntl_virtuemart_orders ON wntl_virtuemart_order_items.virtuemart_order_id = wntl_virtuemart_orders.virtuemart_order_id
WHERE wntl_virtuemart_order_items.order_item_sku BETWEEN 2 and 2.9 AND wntl_virtuemart_order_items.order_status= 'U' AND wntl_virtuemart_orders.customer_number = ?
GROUP BY order_item_sku