子查詢后面要跟子表名稱 (t)
:
SELECT count(*) FROM (
SELECT ap.QUARTER_ID , ar.AREA_NAME , ap.REGION_NAME ,
case WHEN ap.APPLY_TYPE = 1 THEN '集中' WHEN ap.APPLY_TYPE = 2 THEN '增補(bǔ)' ELSE '' END APPLY_TYPE_NAME ,
ap.OUT_APPLY_NO , ac.ACTIVITY_ID , ac.ACTIVITY_NAME , ac.ACTIVITY_BEGIN_DATE ,
ac.ACTIVITY_END_DATE ,
case WHEN ap.RES_TYPE = 1 THEN '物料' WHEN ap.RES_TYPE = 2 THEN '營銷煙' ELSE '' END RES_TYPE_NAME ,
de.RES_ID , re.RES_NAME , de.PRICE , de.COUNT , ROUND((de.PRICE * de.COUNT),4) AS TOTAL_PRICE
FROM out_apply ap
LEFT JOIN activity ac ON ap.ACTIVITY_ID = ac.ACTIVITY_ID
LEFT JOIN base_area ar ON ac.AREA_ID = ar.AREA_ID
LEFT JOIN out_apply_detail de
ON ap.OUT_APPLY_ID = de.OUT_APPLY_ID
LEFT JOIN base_resource re
ON de.RES_ID = re.RES_ID
) t;
這里要跟子表名稱 : (t) , 否則查詢失敗;