我尝试在mysql上的2个表之间进行计算

时间:2011-08-02 05:59:13

标签: mysql

Select sale.preselRef As ref,
  sale.name,
  sale.saledate,
  sale.grandtotal,
  sale.secid,
  sale.invoicetype As typ,
  Sum(sellnote.Paid group by sellnote.Code) As cash,

From sale left joint
  sellnote on ( sale.preselRef = sellnote.Code)

我尝试使用左关节,但我无法使其正确的sql语句,请更正

3 个答案:

答案 0 :(得分:1)

Select sale.preselRef As ref,
    sale.name,
    sale.saledate,
    sale.grandtotal, 
    sale.secid,
    sale.invoicetype As typ,
    Sum(sellnote.Paid) As cash
From sale LEFT JOIN 
    sellnote on ( sale.preselRef = sellnote.Code) 
    GROUP BY sellnote.Code

- 不要把现金放在select语句中的最后一个。 - group by应该放在@ end

答案 1 :(得分:0)

我相信你正在寻找LEFT JOIN

答案 2 :(得分:0)

试试这个:

Select sale.preselRef As ref,
  sale.name,
  sale.saledate,
  sale.grandtotal,
  sale.secid,
  sale.invoicetype As typ,
  Sum(sellnote.Paid group by sellnote.Code) As cash,

From sale left join
  sellnote on ( sale.preselRef = sellnote.Code)