我试图弄清楚如何为每个客户打印一行。当我跑步时

SELECT email_address, sum(quantity * item_price), sum(discount_amount * quantity)
FROM customers JOIN order_items
ORDER BY sum(quantity * item_price)


我只有第一个客户。就价格而言,一切都正确,但仅打印第一个客户。我需要桌子上的所有顾客。有什么建议么?我需要加入任何桌子吗?没有表的连接似乎工作正常。哦,我还需要根据item_price降序排列。任何帮助深表感谢。提前致谢

最佳答案

尝试这样:

SELECT email_address, sum(quantity * item_price), sum(discount_amount * quantity)
FROM customers JOIN order_items on customers.id= order_items.id
GROUP BY (email_address)
ORDER BY sum(quantity * item_price)

关于mysql - 为每个客户mysql返回一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24862626/

10-16 08:24