When each customer has only one purchase, average per customer = average per order. Average can be directly used to calculate average value. The answer is C.
正确答案是:B: No
专业分析:
在一个电商公司的订单表中,每一笔交易都作为单独的一行记录。如果我们直接在订单表中使用 `AVG` 函数来计算平均购买金额,这个计算结果会是所有订单的平均值,而不是每个客户的平均购买金额。
为了计算每个客户的平均购买金额,我们需要先按客户进行分组,然后再计算每个客户的平均购买金额,最后再对这些客户的平均值进行平均计算。具体步骤如下:
1. 按客户ID进行分组,计算每个客户的总购买金额和购买次数。
2. 对每个客户的总购买金额除以购买次数,得到每个客户的平均购买金额。
3. 对所有客户的平均购买金额再取平均值,得到整体的平均购买金额。
在SQL中,这可以通过嵌套查询或CTE(Common Table Expression)来实现。例如:
```sql
WITH CustomerAverages AS (
SELECT
customer_id,
AVG(order_amount) AS avg_purchase_amount
FROM
orders
GROUP BY
customer_id
)
SELECT
AVG(avg_purchase_amount) AS overall_avg_purchase_amount_per_customer
FROM
CustomerAverages;
```
通过这种方式,我们才能正确地计算出每个客户的平均购买金额,并进而求出所有客户的平均值。因此,直接在订单表中使用 `AVG` 函数是无法得到准确的每个客户的平均购买金额的。