0

我有两个表 sales 和 customers 来自第一个表我想将两列 recived_amount 和 bill_amount 相加并减去它们,然后还想得到 customer_id

从第二张桌子我只想得到 Customer_name

我试过了

  SELECT Customer_details.CUS_name, 
       SUM(SALES.Bill_Amount) - SUM(SALES.Recived_Amount),
       Customer_details.Cus_id
  from sales 
  INNER JOIN Customer_details 
       ON Customer_details.Cus_id=sales.Cus_id
  where SALES.Cus_id = 1 order BY Cus_id
4

2 回答 2

1
 SELECT Customer_details.CUS_name, (SUM(SALES.Bill_Amount) - SUM(SALES.Recived_Amount)) as       Subtract,Customer_details.Cus_id

 from sales INNER JOIN Customer_details ON Customer_details.Cus_id=sales.Cus_id

 where SALES.Cus_id = 1 

 group by Customer_details.CUS_name,Customer_details.Cus_id

 order BY Cus_id
于 2013-08-15T19:52:43.140 回答
0
SELECT Customer_details.CUS_name,
       (SUM(SALES.Bill_Amount)-SUM(SALES.Recived_Amount)) AS Balance_Owed,
       Customer_details.Cus_ID
FROM Sales INNER JOIN Customer_details ON Customer_details.Cus_id=Sales.Cus_id
GROUP BY Customer_details.CUS_name,Customer_details.Cus_id
ORDER BY Customer_details.Cus_id;
于 2013-08-15T20:19:40.110 回答