sql - 如何在第二个 GROUP BY 语句期间重新汇总值
问题描述
正如您在右侧看到的,这些值是从前一个 group by 的 sum() 函数中获得的,但我在表中仍然有非唯一的名称。我怎样才能使表中的所有名称都是唯一的,并且右侧的值对非唯一成员求和。
这是我的查询,以防有帮助:
select alp_customer.first, alp_customer.last, alp_customer.email, sum(alp_orderline.order_price)
from alp_orderline
inner join alp_orders on alp_orderline.order_id = alp_orders.order_id
inner join alp_customer on alp_orders.cust_id = alp_customer.cust_id
group by alp_orderline.order_id
我希望我的问题足够清楚,我对 SQL 很陌生,无法在线找到解决方案。
解决方案
在 group by 中使用 alp_customer.first, alp_customer.last, alp_customer.email
这些列
select alp_customer.first, alp_customer.last, alp_customer.email, sum(alp_orderline.order_price)
from alp_orderline
inner join alp_orders on alp_orderline.order_id = alp_orders.order_id
inner join alp_customer on alp_orders.cust_id = alp_customer.cust_id
group by alp_customer.first, alp_customer.last, alp_customer.email
推荐阅读
- tensorflow - CNN 准确率增加,而损失减少增加
- c# - C# - 'int' 和
- swift - Swift 错误答案中的迭代中序遍历
- postgresql - 如何优化超表的插入速度?
- python - 在 Google Cloud 机器学习引擎上训练 TensorFlow 对象检测模型时出错
- coded-ui-tests - 无法在编码的 ui 中获取 WinTable 的列标题
- c# - $facet 没有反序列化
- android - 如何将 asm 代码块嵌入到使用 clang 编译并将在 Android 上运行的 c 程序中
- linux - bash 脚本从 bash 脚本添加 git 凭据
- php - 可以将数组添加到我的创建方法吗?