如何组合这两组代码?
表格:geregistreerd g
,乐器i
和插入id
。
我要显示g.voornaammuzikant
,g.achternaammuzikant
,i.naaminstrument
,id.familie
。
表g
通过i
与表instrumentid
链接
表i
与表ID和indelingid
链接
-强化1:
SELECT TRIM(' ' FROM g.voornaammuzikant), TRIM(' ' FROM g.achternaammuzikant),
(SELECT i.naaminstrument
from instrument i
where i.instrumentid = g.instrumentid) as "naam instrument"
from geregistreerd g
order by g.voornaammuzikant;
-强化2:
SELECT i.naaminstrument,
(SELECT id.familie
from indeling id
where i.indelingid = id.indelingid) as "familie",
(SELECT id.onderfamilie
from indeling id
where i.indelingid = id.indelingid) as "onderfamilie"
from instrument i
order by i.naaminstrument;
组合
SELECT TRIM(' ' FROM g.voornaammuzikant),
TRIM(' ' FROM g.achternaammuzikant),
(SELECT i.naaminstrument
(SELECT id.familie
from indeling id
where i.indelingid = id.indelingid) as "familie"
from instrument i
where i.instrumentid = g.instrumentid) as "naam instrument"
from geregistreerd g
order by g.voornaammuzikant;
答案 0 :(得分:0)
如果可以简化事情,为什么要以复杂的方式做事情?简单的联接有什么问题?像这样:
select g.voornaammuzikant,
g.achternaammuzikant,
i.naaminstrument,
id.familie
from geregistreerd g join instrument i on i.instrumentid = g.instrumentid
join indeling id on id.indelingid = i.indelingid
order by g.voornaammuzikant;
顺便说一句,您发布的TRIM
看起来不太好。 SELECT TRIM(' ' FROM g.voornaammuzikant)
当然是错误的;我不知道你想说什么。也许从这些值中删除多余的空间?如果存在,那么-该列的数据类型是否为CHAR
?如果是这样,请考虑切换到VARCHAR2
,因为前者将值填充到该列的整个长度为止。