SQL - 与聚合混淆
我目前有这个查询:
select
customers.emailaddress,
MAX(orders.orderdate) as "last order"
from orders
join customers
on orders.customerID = customers.customerID
group by customers.emailaddress
这给了我电子邮件和最后订单日期。在“Orders”表中,有一个名为“PaymentTotal”的字段,如何根据 MAX(orders.orderdate) 返回的值获取该字段? (即我试图获取每封电子邮件的最后一个订单的金额)
I currently have this query:
select
customers.emailaddress,
MAX(orders.orderdate) as "last order"
from orders
join customers
on orders.customerID = customers.customerID
group by customers.emailaddress
Which gives me the emails, and the last order date. With the 'Orders' table, there is a field named 'PaymentTotal', how can I get this based on the value returned by MAX(orders.orderdate)? (ie am trying to get the amount of the last order per email)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)