Below is expected results 以下是我实际开展工作的代码,但如果没有完成采购,则会返回一个空白行
SELECT PRJ$Projects.project_id
,VW_QUOTE_SECTION_TOTALS.Quoted_section_total "Amount"
,VW_SECTION_TOTALS.Costed_section_total "Quoted Budget"
,(VW_QUOTE_SECTION_TOTALS.Quoted_section_total - VW_SECTION_TOTALS.Costed_section_total) "Gross Profit"
,ROUND(((VW_QUOTE_SECTION_TOTALS.Quoted_section_total - VW_SECTION_TOTALS.Costed_section_total) / VW_QUOTE_SECTION_TOTALS.Quoted_section_total) * 100) "GP %"
,ROUND(VW_PROC_SUM.total, 2) "Procured"
,(VW_SECTION_TOTALS.Costed_section_total - VW_PROC_SUM.total)
FROM PRJ$Projects
INNER JOIN prj$quotes ON prj$quotes.PROJECT_ID = PRJ$Projects.PROJECT_ID
AND PRJ$Projects.QUOTE_TOTAL IS NOT NULL
INNER JOIN VW_PROC_SUM ON VW_PROC_SUM.PROJECT_ID = PRJ$Projects.PROJECT_ID
INNER JOIN prj$quote_sections ON prj$quote_sections.quote_id = prj$quotes.quote_id
INNER JOIN VW_SECTION_TOTALS ON VW_SECTION_TOTALS.QUOTE_SECTION_ID = prj$quote_sections.QUOTE_SECTION_ID
INNER JOIN VW_QUOTE_SECTION_TOTALS ON VW_QUOTE_SECTION_TOTALS.QUOTE_SECTION_ID = prj$quote_sections.QUOTE_SECTION_ID
AND prj$quote_sections.quote_section_id = :P13_SECT_ID_H