code
打印一个包含play ID
,play title
,play year
列的表格,其中包含按播放年份排序的表格中的值
我想将戏剧,喜剧,悲剧表添加到巨大的表格中的一列中。
因此,表格的打印方式如下:每列下方的值:
P_NO
,P_TITLE
,P_YEAR
,TYPE
TYPE是
select d.D_TYPE as "TYPE" from DRAMA d where d.D_P_NO=p.P_NO
UNION
select c.C_TYPE as "TYPE" from COMEDY c where c.C_P_NO=p.P_NO
UNION
select t.T_TYPE as "TYPE" from TRAGEDY t where t.T_P_NO=p.P_NO
所以我的问题是如何将表TYPE添加到SYNTAX is CORRECT
的下面的代码中并且因为我的上述声明是错误的而且不能用于JOIN表
代码:
select p.P_NO, cast(p.P_TITLE as varchar(15)) as P_TITLE, p.P_YEAR
from PLAY p
order by p.P_YEAR
答案 0 :(得分:0)
可能你正在寻找这个
select p.P_NO,
cast(p.P_TITLE as varchar(15)) as P_TITLE,
p.P_YEAR ,
(select d.D_TYPE as "TYPE"
from DRAMA d
where d.D_P_NO=p.P_NO
UNION
select c.C_TYPE as "TYPE"
from COMEDY c
where c.C_P_NO=p.P_NO
UNION
select t.T_TYPE as "TYPE"
from TRAGEDY t
where t.T_P_NO=p.P_NO
) as TYPE
from PLAY p
order by p.P_YEAR