建这样一个视图,多个表相同结构,具体需求如下
表1 字段: id,caller,callee,calltime,callfee
表2 字段,表3.........表7 结构都是同上....
需求1 建视图v_caller,联合这7个表,
能实现如下 sql 语句1 select caller from v_caller where caller= '13900000000 ' group by caller having sum(callfee) > 100
2 select caller from v_caller where caller= '13900000000 ' group by caller having count(caller)> 2
这样的 view 怎么建?
------解决方案--------------------create view v_caller
as
select * from T1
union all
select * from T2
union all
...
------解决方案--------------------create view v_caller
as
select caller from
(
select * from T1
union all
select * from T2
union all
......
select * from T7
) t
where caller= '13900000000 ' group by caller having sum(callfee) > 100
------解决方案--------------------create view v_caller
as
select caller
from
(
select * from T1
union all
select * from T2
union all
select * from T3
union all
select * from T4
union all
select * from T5
union all
select * from T6
union all
select * from T7
) t
where caller= '13900000000 '
group by caller
having sum(callfee) > 100