<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="io.renren.modules.app.dao.SanlszzDao">
	<select id="sanlszzSelect" parameterType="io.renren.modules.app.entity.SanlszzEntity" resultType="io.renren.modules.app.entity.SanlszzEntity">
	select kjqj,pzh,zy,jfje,dfje,ifnull(qcye,'0.0') qcye,ss ,kmsx ,#{hskmdm} hskmdm,kmmc from
          (
       select concat(substring_index(#{kjqj},"-",1),'-01') kjqj,0 pzh,'期初余额' zy,0 jfje,0 dfje, sum(qcye) qcye,'0' ss,#{kmsx} kmsx,'' kmmc  from h_kmye
               where ztbm = #{ztbm} and   kjqj = concat(substring_index(#{kjqj},"-",1),'-01') and hskmdm like '${hskmdm}%'
       union all
       select kjqj,count(distinct pzh) pzh, kjqj zy ,sum(jfje) jfje,sum(dfje) dfje ,0 as qcye , '1' ss ,#{kmsx} kmsx,kmmc from h_pz,h_km
          where h_pz.ztbm = #{ztbm} and h_pz.km like '${hskmdm}%' and substring_index(kjqj,"-",1) = substring_index(#{kjqj},"-",1) and h_km.km =h_pz.km
          group by kjqj
       ) sns
		order by kjqj,pzh
	</select>
    

</mapper>
