数据库sql查询语句转换成ibatis中xml里的语句,帮转换一下!
selecta.state_tm_m,a.mt_number,a.mo_number,a.sp_name,a.corp_id,a.svc_id,(a.mo_number+...
select a.state_tm_m,a.mt_number,a.mo_number,a.sp_name,a.corp_id,a.svc_id,(a.mo_number+a.mt_number-b.mo_number-b.mt_number)
as flow_change, (a.mo_number+a.mt_number-b.mo_number-b.mt_number)/(b.mo_number+b.mt_number)*100||'%' as flow_change_rate
from
(select substr(state_tm_m,0,6) as state_tm_m,sum(mt_number) as mt_number,sum(mo_number) as mo_number,sp_name,corp_id,svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m,0,6) between 201311 and 201403
group by substr(state_tm_m,0,6),sp_name,corp_id,svc_id) a,
(select substr(state_tm_m,0,6) as state_tm_m,sum(mt_number) as mt_number,sum(mo_number) as mo_number,sp_name,corp_id,svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m,0,6) between 201310 and 201402
group by substr(state_tm_m,0,6),sp_name,corp_id,svc_id) b where a.svc_id = b.svc_id and a.corp_id=b.corp_id and
a.state_tm_m-1=b.state_tm_m
order by flow_change_rate; 展开
as flow_change, (a.mo_number+a.mt_number-b.mo_number-b.mt_number)/(b.mo_number+b.mt_number)*100||'%' as flow_change_rate
from
(select substr(state_tm_m,0,6) as state_tm_m,sum(mt_number) as mt_number,sum(mo_number) as mo_number,sp_name,corp_id,svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m,0,6) between 201311 and 201403
group by substr(state_tm_m,0,6),sp_name,corp_id,svc_id) a,
(select substr(state_tm_m,0,6) as state_tm_m,sum(mt_number) as mt_number,sum(mo_number) as mo_number,sp_name,corp_id,svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m,0,6) between 201310 and 201402
group by substr(state_tm_m,0,6),sp_name,corp_id,svc_id) b where a.svc_id = b.svc_id and a.corp_id=b.corp_id and
a.state_tm_m-1=b.state_tm_m
order by flow_change_rate; 展开
2013-03-18
展开全部
看你的SQL里面一共是两个条件吧,分别是内查询
where substr(state_tm_m,0,6) between 201311 and 201403
和
where substr(state_tm_m,0,6) between 201310 and 201402
每个条件里面有两个变量,这样的话,应该是从dao里面传入4个变量吧,直接把这四个变量替换一下即可,如:
select a.state_tm_m,
a.mt_number,
a.mo_number,
a.sp_name,
a.corp_id,
a.svc_id,
(a.mo_number + a.mt_number - b.mo_number - b.mt_number) as flow_change,
(a.mo_number + a.mt_number - b.mo_number - b.mt_number) /
(b.mo_number + b.mt_number) * 100 || '%' as flow_change_rate
from (select substr(state_tm_m, 0, 6) as state_tm_m,
sum(mt_number) as mt_number,
sum(mo_number) as mo_number,
sp_name,
corp_id,
svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m, 0, 6) between #{start1} and #{end1}
group by substr(state_tm_m, 0, 6), sp_name, corp_id, svc_id) a,
(select substr(state_tm_m, 0, 6) as state_tm_m,
sum(mt_number) as mt_number,
sum(mo_number) as mo_number,
sp_name,
corp_id,
svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m, 0, 6) between #{start2} and #{end2}
group by substr(state_tm_m, 0, 6), sp_name, corp_id, svc_id) b
where a.svc_id = b.svc_id
and a.corp_id = b.corp_id
and a.state_tm_m - 1 = b.state_tm_m
order by flow_change_rate;
其中:#{start1} #{end1} #{start2} #{end2}
分别为你从services传进来的参数,根据你的参数类型而定
如果是对象的话,可以直接引用其属性,如:
#{obj.start1} #{obj.end1} #{obj.start2} #{obj.end2}
你先试一下吧,有问题再回复
where substr(state_tm_m,0,6) between 201311 and 201403
和
where substr(state_tm_m,0,6) between 201310 and 201402
每个条件里面有两个变量,这样的话,应该是从dao里面传入4个变量吧,直接把这四个变量替换一下即可,如:
select a.state_tm_m,
a.mt_number,
a.mo_number,
a.sp_name,
a.corp_id,
a.svc_id,
(a.mo_number + a.mt_number - b.mo_number - b.mt_number) as flow_change,
(a.mo_number + a.mt_number - b.mo_number - b.mt_number) /
(b.mo_number + b.mt_number) * 100 || '%' as flow_change_rate
from (select substr(state_tm_m, 0, 6) as state_tm_m,
sum(mt_number) as mt_number,
sum(mo_number) as mo_number,
sp_name,
corp_id,
svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m, 0, 6) between #{start1} and #{end1}
group by substr(state_tm_m, 0, 6), sp_name, corp_id, svc_id) a,
(select substr(state_tm_m, 0, 6) as state_tm_m,
sum(mt_number) as mt_number,
sum(mo_number) as mo_number,
sp_name,
corp_id,
svc_id
from gsg_stat_ecsi_day_tab
where substr(state_tm_m, 0, 6) between #{start2} and #{end2}
group by substr(state_tm_m, 0, 6), sp_name, corp_id, svc_id) b
where a.svc_id = b.svc_id
and a.corp_id = b.corp_id
and a.state_tm_m - 1 = b.state_tm_m
order by flow_change_rate;
其中:#{start1} #{end1} #{start2} #{end2}
分别为你从services传进来的参数,根据你的参数类型而定
如果是对象的话,可以直接引用其属性,如:
#{obj.start1} #{obj.end1} #{obj.start2} #{obj.end2}
你先试一下吧,有问题再回复
追问
#{obj.end1} 中的 obj是什么?是pojo类吗?
我在xml中怎么调用pojo类里的方法?
追答
是的obj 是一个pojo类的对象
不好意思,xml 中无法调用 pojo 类里面的方法
但是你的 pojo 里面肯定有 getter、setter方法
直接访问你的 pojo 类的属性即可,如:
${obj.name}
ibatis它自己会调用 getName() 方法
展开全部
你把where语句中的会变得值换成变量就是了
比如where substr(state_tm_m,0,6) between 201311 and 201403这句,
你的201311和201403应该是变量传值吧
写成这样子
where 1=1
<if test="date!=null and date!='' ">
and substr(state_tm_m,0,6) between #{date}and #{date}
</if>
其中date是传入参数对象searcher的一个变量名
resultMap是返回值对应的映射文件
你要先确定你这个SQL语句是正确的,再改成上面这样子的吧
<select id="getTargetList" parameterType="searcher"
resultType="list" resultMap="taxiMonthRateMap">
//这里放你写好的改好了的sql语句
</select>
当含有大于或者小于符号的语句时,切记使用
<![CDATA[
//该语句
]]>
比如where substr(state_tm_m,0,6) between 201311 and 201403这句,
你的201311和201403应该是变量传值吧
写成这样子
where 1=1
<if test="date!=null and date!='' ">
and substr(state_tm_m,0,6) between #{date}and #{date}
</if>
其中date是传入参数对象searcher的一个变量名
resultMap是返回值对应的映射文件
你要先确定你这个SQL语句是正确的,再改成上面这样子的吧
<select id="getTargetList" parameterType="searcher"
resultType="list" resultMap="taxiMonthRateMap">
//这里放你写好的改好了的sql语句
</select>
当含有大于或者小于符号的语句时,切记使用
<![CDATA[
//该语句
]]>
更多追问追答
追问
百度HI加你好友了 ,百度HI里说。
追答
你就按照我说的那样子改改吧,我也是才开始使用这个,不是很熟悉的。有什么问题再说
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询