我有三个表:a , b ,c ;
现在要创建一个视图,把上述三表中各自的ID和Name列提取出来
并在视图中增加一列“来源ID”
把来自表a的那些项的来源ID那一栏置为1,
把来自表b的那些项的来源ID那一栏置为2,
把来自表c的那些项的来源ID那一栏置为3,
视图出来的实例应该是:
ID Name S_ID
====================
01 aa1 01
02 aa2 01
01 bb1 02
01 cc1 03
大虾们谁会创建这个视图啊???小生感激不尽阿!!!
现在要创建一个视图,把上述三表中各自的ID和Name列提取出来
并在视图中增加一列“来源ID”
把来自表a的那些项的来源ID那一栏置为1,
把来自表b的那些项的来源ID那一栏置为2,
把来自表c的那些项的来源ID那一栏置为3,
视图出来的实例应该是:
ID Name S_ID
====================
01 aa1 01
02 aa2 01
01 bb1 02
01 cc1 03
大虾们谁会创建这个视图啊???小生感激不尽阿!!!
union all
select id,name,S_ID='02' from b
union all
select id,name,S_ID='03' from c
as
select id,name,'01' as s_id
from a
union all
select id,name,'02' as s_id
from b
union all
select id,name,'03' as s_id
from cgo
as
select id,name,frm=1 from tbA
union all
select id,name,frm=2 from tbB
union all
select id,name,frm=3 from tbC
as
select A.id,A.name,'01' as S_id from A
union
select B.id,B.name,'02' from B
union
select C.id,C.name,'03' from C
---------------------------------------------
难道是在说我?
刚上CSDN就碰到这师,没办法,建议LZ不要给我会就是了~~~
还有,就是我刚才创建了那个视图,但是视图的三列的那个名字不对
我本来想要的结果是:ID Name S_ID
但因为表A里面是SYS_ID和SYS_name
现在出来的视图里面的三列是SYS_ID SYS_name S_ID
这个怎么改成ID Name和S_ID阿??
union all
select SYS_ID as id,SYS_name as name,S_ID='02' from b
union all
select SYS_ID as id,SYS_name as name,S_ID='03' from c