SQL left join 查询
with tb1 as
(select count(uid) as totalregister,ggsiteid
from UserSystem where ggsiteid
in(select code from PromotionCode where scode=102013)
and ( regdate between '2013-03-05' and '2013-03-08') group by ggsiteid )
, tb2 as
(select sum(a.paymoney) as totalmoney,count(distinct(a.uid)) as totalpay,
b.ggsiteid
from user_czhistory as a
left join
(select regdate,uid,ggsiteid from usersystem
where ggsiteid in(select code from PromotionCode where scode=102013)
and regdate>='2013-03-05' and regdate<'2013-03-08'
)
as b
on a.uid=b.uid
where a.updatetime<=dateadd(dd,1,b.regdate)
group by b.ggsiteid)
select * from tb1 left join tb2
on tb1.ggsiteid=tb2.ggsiteid
表tb1数据:
1516 1116
1459 1117
3457 1118
890 1119
1031 1122
如果表tb2数据为:
30 1 1117
查询超慢,不出来
如果数据为:
290 5 1117
610 3 1118
1000 2 1119
10 1 1122
则可以查询出来
这是什么原因