列出客户的名字,姓氏和花费的总金额(注意:花费的金额是订单小计+税金+从tblorder表中发货的成本)。
我有这段代码(但价值都是一样的:
Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent
From tblorder,tblcust
group by name
答案 0 :(得分:0)
这应该这样做:
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;
(两者都应该给出相同的结果)