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
则可以查询出来
这是什么原因
(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
则可以查询出来
这是什么原因
...全文
相关推荐
Hive查询sql left join exists
总的来说,理解和熟练运用LEFT JOIN、LEFT SEMI JOIN以及EXISTS子句是Hive SQL查询中的关键技能,它们在大数据分析中扮演着重要角色,帮助用户从海量数据中提取有价值的信息。
MySQL利用profile分析慢sql详解(group left join效率高于子查询)
本文主要介绍了如何使用MySQL的Profiler来分析慢SQL,并且通过对比GROUP BY LEFT JOIN与子查询的效率,展示了SQL优化的一种方法。在MySQL数据库管理中,当遇到性能
11-03 关联查询(左联结(LEFT JOIN)).sql
11-03 关联查询(左联结(LEFT JOIN)).sql
SQL语句优化之JOIN和LEFT JOIN 和 RIGHT JOIN语句的优化
SQL语句优化对于大型数据库系统至关重要,特别是在涉及多表查询时,JOIN、LEFT JOIN 和 RIGHT JOIN 的高效运用能显著提升查询速度。
SQL left join
三、SQL Left Join与Right Join、Inner Join的区别 SQL Left Join、Right Join和Inner Join都是用于组合表数据的查询操作,但它们之间存在着明显的区别


应用实例
