Oracle的SQL中如何将动态生成的列进行相加 要TEU=20GP+2*(40GP+40HC)
发布网友
发布时间:2022-04-23 00:57
我来回答
共4个回答
热心网友
时间:2023-10-09 15:58
如果需要保留20GP等,那么再加一层即可:
select a.*, "20GP" + 2*("40GP" + "40HC") as TEU
from (
SELECT PORT.CNAME AS PORTLOAD,
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '20' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) ) AS "20GP",
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) ) AS "40GP",
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'HC' and bo.boid = bkctn.boid(+) ) AS "40HC",
BO.ETD,
BO.VOY,
FROM BO,PORT
WHERE BO.PORTLOAD=PORT.PORT
) a
如果不需要保留,直接相加:
SELECT PORT.CNAME AS PORTLOAD,
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '20' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) )
+ 2*( (select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) ) + (select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'HC' and bo.boid = bkctn.boid(+) ) ) AS TEU,
BO.ETD,
BO.VOY,
FROM BO,PORT
WHERE BO.PORTLOAD=PORT.PORT
热心网友
时间:2023-10-09 15:58
select a.*,"20GP"+2*("40GP"+"40HC") TEU
(SELECT PORT.CNAME AS PORTLOAD,
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '20' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) ) AS "20GP",
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) ) AS "40GP",
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'HC' and bo.boid = bkctn.boid(+) ) AS "40HC",
BO.ETD,
BO.VOY,
FROM BO,PORT
WHERE BO.PORTLOAD=PORT.PORT
) a追问还是不行
热心网友
时间:2023-10-09 15:59
SELECT PORTLOAD,20GP+2*(40GP+40HC) AS TEU FROM (SELECT PORT.CNAME AS PORTLOAD,
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '20' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) ) AS "20GP",
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'GP' and bo.boid = bkctn.boid(+) ) AS "40GP",
(select BKCTN.PNUM
from bkctn
where CTNSIZE = '40' AND CTNTYPE = 'HC' and bo.boid = bkctn.boid(+) ) AS "40HC",
BO.ETD,
BO.VOY,
FROM BO,PORT
WHERE BO.PORTLOAD=PORT.PORT)
热心网友
时间:2023-10-09 15:59
select 20GP+2*(40GP+40HC) from al