使用连接在我的SQL中显示空行

时间:2012-06-19 15:41:24

标签: mysql

在以下查询的帮助下,我只能获取15行但实际行数为16 一行为空

所以我怎样才能获取那一行呢?我应该得到16行,请帮帮我......

select p.partnerid,p.name,count(*) as accounts,sum(c.amount) as amount,sum(c.netamt) as netamt,
sum(c.netamt - c.amount) as interest,
sum(case when c.installment = 20 then c.amount else 0 end) as Twenty,
sum(case when c.installment = 10 then c.amount else 0 end) as Ten,
sum(case when c.installment = 5 then c.amount else 0 end) as Five,
sum(case when c.installment = 2 then c.amount else 0 end) as Two
from partnerinfo p left outer join customerinfo c on p.partnerid = c.partnerid
where c.startdate >= '2011-3-15' and c.startdate <= '2012-12-30' and p.manager=1 group by p.partnerid

即使我将日期从2011-3-15更改为2012-3-15空行应该显示。 我尝试了最好的水平,却无法实现。

请帮帮我......

1 个答案:

答案 0 :(得分:0)

试试这个:

select p.partnerid,p.name,count(*) as accounts,sum(c.amount) as amount,sum(c.netamt) as netamt,
sum(c.netamt - c.amount) as interest,
sum(case when c.installment = 20 then c.amount else 0 end) as Twenty,
sum(case when c.installment = 10 then c.amount else 0 end) as Ten,
sum(case when c.installment = 5 then c.amount else 0 end) as Five,
sum(case when c.installment = 2 then c.amount else 0 end) as Two
from partnerinfo p left outer join customerinfo c on p.partnerid = c.partnerid
where (c.startdate is null OR (c.startdate >= '2011-3-15' and c.startdate <= '2012-12-30')) 
and (p.manager is null OR p.manager=1)
group by p.partnerid