如何将表和视图合并到一个查询中?我有两个Select语句,一个是内连接,我想在第二个选择中组合表和视图,并进行一个查询。
SELECT PROJECT.PROJ_ID,
PROJECT.HULL_NUM_ID,
PROJECT.SHIP_TYPE_CD,
PROJECT.PROJ_NM,
ICP_SUMMARY.MOD_STOP_DT
FROM BAIM.ICP_SUMMARY ICP_SUMMARY
INNER JOIN BAIM.PROJECT PROJECT
ON ICP_SUMMARY.PROJ_ID = PROJECT.PROJ_ID
SELECT ICP_SUMMARY_JS_VW.PROJ_ID,
ICP_SUMMARY_JS_VW.LBR_EST_MANDAYS,
ICP_SUMMARY_JS_VW.LBR_ICP_MANDAYS,
ICP_SUMMARY_JS_VW.MATL_EST_COST,
ICP_SUMMARY_JS_VW.MATL_ICP_COST,
ICP_SUMMARY_JS_VW.TOTAL_EST_COST,
ICP_SUMMARY_JS_VW.TOTAL_ICP
FROM BAIM.ICP_SUMMARY_JS_VW ICP_SUMMARY_JS_VW
答案 0 :(得分:2)
您可以像对待桌子一样对待视图。您可以对视图执行连接,并且您可以在select语句中拥有所需的视图。
答案 1 :(得分:1)
您只需要在表格和视图上JOIN
,类似于:
SELECT PROJECT.PROJ_ID,
PROJECT.HULL_NUM_ID,
PROJECT.SHIP_TYPE_CD,
PROJECT.PROJ_NM,
ICP_SUMMARY.MOD_STOP_DT,
ICP_SUMMARY_JS_VW.PROJ_ID,
ICP_SUMMARY_JS_VW.LBR_EST_MANDAYS,
ICP_SUMMARY_JS_VW.LBR_ICP_MANDAYS,
ICP_SUMMARY_JS_VW.MATL_EST_COST,
ICP_SUMMARY_JS_VW.MATL_ICP_COST,
ICP_SUMMARY_JS_VW.TOTAL_EST_COST,
ICP_SUMMARY_JS_VW.TOTAL_ICP
FROM BAIM.ICP_SUMMARY ICP_SUMMARY
INNER JOIN BAIM.PROJECT PROJECT
ON ICP_SUMMARY.PROJ_ID = PROJECT.PROJ_ID
INNER JOIN BAIM.ICP_SUMMARY_JS_VW ICP_SUMMARY_JS_VW -- do JOIN Here
ON ICP_SUMMARY.PROJ_ID = ICP_SUMMARY_JS_VW.PROJ_ID -- select the field to JOIN on