列出客户的名字、姓氏和花费的总金额(注意:花费的金额是订单小计 + 税费 + tblorder 表中的运输费用)。
我有这个代码(但值都是一样的:
Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent
From tblorder,tblcust
group by name
最佳答案
这应该可以做到:
Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent
From tblorder a
inner join tblcust b ON a.custId=b.custId
group by name;
您没有定义要加入表格的内容。
在您的代码风格中,这将是:
Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent
From tblorder a,tblcust b
where a.custId=b.custId
group by name;
(两者应该给出相同的结果)
关于Mysql 选择总计和名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29404364/