我应该从表产品中添加一个新行,其所有者为sales(sh)到product_name_us,prod_desc到product_desc_us并使用联合。
SELECT temp.*
FROM (SELECT DISTINCT CASE WHEN pd.LANGUAGE_ID = 'US' THEN
COALESCE(TO_CHAR(pd.TRANSLATED_NAME), ' ')
END AS PRODUCT_NAME_US,
CASE WHEN pd.LANGUAGE_ID = 'US' THEN
CONCAT(SUBSTR(pd.TRANSLATED_DESCRIPTION, 1, 30), '...')
END AS PRODUCT_DESC_US,
CASE WHEN pd.LANGUAGE_ID = 'RU' AND pd.translated_name
IS NULL THEN COALESCE(TO_CHAR(pd.TRANSLATED_NAME), ' ')
END AS PRODUCT_NAME_RU,
CASE WHEN pd.LANGUAGE_ID = 'RU' AND
pd.translated_description IS NULL THEN
CONCAT(SUBSTR(pd.TRANSLATED_DESCRIPTION, 1, 30), '...')
END AS PRODUCT_DESC_RU,
CASE
WHEN EXTRACT(MONTH FROM pin.WARRANTY_PERIOD) =
'00' THEN EXTRACT(YEAR FROM pin.WARRANTY_PERIOD) || ' years'
END AS "Warranty", inv.QUANTITY_ON_HAND AS IN_STOCK
FROM PRODUCT_DESCRIPTIONS pd JOIN PRODUCT_INFORMATION pin
ON pd.PRODUCT_ID = pin.PRODUCT_ID
JOIN INVENTORIES inv
ON inv.PRODUCT_ID = pin.PRODUCT_ID) temp
WHERE temp.PRODUCT_NAME_US LIKE '%Monitor%'
AND temp.IN_STOCK < 100
union all (select PROD_NAME,PROD_DESC from sh.products);
答案 0 :(得分:0)
如果我理解正确,您想在第一行中添加一行作为页脚。 仅当您的2个选择的列数相同时,才能使用并集
select 'field1' as a, 'field2' as b, 'field3' as c from dual
union all
select '1', '2', null from dual;
但是,如果要在第一个查询列中使用第二个查询列进行匹配,那是不可能的,因为它不在select语句之内