2015-04-02 39 views
0

列出客戶的名字,姓氏和花費總金額(注意:花費的金額是訂單小計+稅金+從tblorder表中發貨的成本)。Mysql select總計和名稱

我有這樣的代碼(但值都出來一樣:

Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent 
From tblorder,tblcust 
group by name 

my queries

+1

嘗試把你的表之間的連接條件。作爲一條規則:不要在'from'子句中使用逗號。始終使用明確的「加入」。 – 2015-04-02 03:11:04

+0

idk要加入的是它的名稱和custid? – runlax 2015-04-02 03:15:54

回答

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; 

(兩者應該給予同樣的結果)