SQL left join 查询

zhangzhenshuang zhangzhenshuang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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
则可以查询出来
这是什么原因
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
zhangzhenshuang
应用实例 27,579 成员 68,540 内容