select '单据' name,sum(amount) amount1,'元' type,'q' sort
from FINANCE_CHECK_MNG where modeltype='project_model' and createtime >= '2014-01-01 0:00:00' and createtime <='2014-12-31 0:00:00'
union
select '单据' name,sum(amount) amount2,'元' type,'q' sort
from FINANCE_CHECK_MNG where modeltype='project_model' and createtime >= '2012-12-01 0:00:00' and createtime <='2012-12-31 0:00:00'
这样算出的数据格式是:
name amount1 type sort
单据 5560.00 元 q
单据 129901.42 元 q
现在需要的数据格式是:
name amount1 type sort
单据 当前年:5560.00/当前月:129901.42 元 q
------解决方案--------------------
select a.[name],('当前年:'+a.amount1+'/当前月:'+b.amount2) as amount1,a.[type],a.sort
from
(
select '单据' name,sum(amount) amount1,'元' type,'q' sort
from FINANCE_CHECK_MNG where modeltype='project_model' and createtime >= '2014-01-01 0:00:00' and createtime <='2014-12-31 0:00:00'
) a left join
(
select '单据' name,sum(amount) amount2
from FINANCE_CHECK_MNG where modeltype='project_model' and createtime >= '2012-12-01 0:00:00' and createtime <='2012-12-31 0:00:00'
) b on a.[name]=b.[name]