我写的Oracle语法,你看看和MySQL有什么出入的地方改一改就可以了,应该差不多,我不知道你的A表的id和B表的id是否关联,如果不关联一个SQL语句实现不了,会出现冗余的笛卡尔积,
---A表和B表ID关联create or replace view view_name
as
select t1.id,
sum(t1.xx) x,
sum(t2.yy) y,
sum(t1.xx+t2.yy) z
from A t1,
B t2
where t1.id = t2.id
group by t1.id
select"reg",regtime,count(1)
as
cnt
from
table1
where
regtime>='2013-10-1'
and
regtime<'2013-11-1''
union
select
"last",lastestlogintime,count(1)
as
cnt
from
table1
where
lastestlogintime>='2013-10-1'
and
lastestlogintime<'2013-11-1'
结果会有两行,第一行是注册数量,第二行是登录数量
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)