select * from ( select b.INVEST_AMOUNT 投资金额, b.month_id yy, d.year_id, substr(b.MONTH_ID, 5, 2) mm from INDUSTRY_PROJECT a, FACT_INDUSTRY_PROJECT_BOOST b, INDUSTRY_PROJECT_YEAR_TARGET d, DIM_PUBLIC_MONTH f where a.INDUSTRY_PROJECT_ID = d.INDUSTRY_PROJECT_ID and a.INDUSTRY_PROJECT_ID = b.INDUSTRY_PROJECT_ID and b.month_id = f.month_id and d.year_id = f.year_id and b.month_id = '${month_id_m}' group by b.INVEST_AMOUNT, b.month_id, d.year_id, substr(b.MONTH_ID, 5, 2) order by b.month_id) a, (select max(MONTH_ID) max_month,month_id from FACT_INDUSTRY_PROJECT_BOOST) b where a.yy = b.month_id ${if(len(month_id_m) == 0,"and a.mm <= SUBSTR(b.max_month, 5, 2)","and a.mm <= SUBSTR(' month_id_m', 5, 2) ")} 以上SQL在查出数据后 主要想实现按时间查找数据! 首先有一个查询参数 ${month_id_m} 是按月查询 ,格式为“201304” 在默认情况下,参数为空,则根据库里已有的数据抽取当前年1月份——最大月份(最近月份)‘max_month’ 同时可利用参数查询(时间控件),按月查询 SQL里面存在问题,可能是低级错误或者逻辑问题,希望大神们劳心给看下!!并给与指正!! 谢谢!! |