Blame view

src/main/resources/mybatis/inventory/InventoryChangesMapper.xml 1.39 KB
1
2
3
4
5
6
7
<?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="com.huaheng.pc.inventory.report.mapper.InventoryChangesMapper">

    <select id="select" resultType="com.huaheng.pc.inventory.report.domain.InventoryChanges">
yuxiao authored
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
        select a.created,IFNULL(count,0)  count,materialCode from (
        select DATE_FORMAT(d.m, '%Y-%m') created
        from(
        select
        ( #{startTime} -  INTERVAL DAYOFMONTH(#{endTime})-1 DAY)
        +INTERVAL m MONTH as m
        from(
        select @rownum:=@rownum+1 as m from
        (select 1 union select 2 union select 3 union select 4) t1,
        (select 1 union select 2 union select 3 union select 4) t2,
        (select 1 union select 2 union select 3 union select 4) t3,
        (select 1 union select 2 union select 3 union select 4) t4,
        (select @rownum:=-1) t
        ) d1
        ) d
        where m &lt;= #{endTime}
        order by created ) a left join
25
        (SELECT
yuxiao authored
26
        DATE_FORMAT( created, '%Y-%m' ) created,
27
28
29
        sum( qty ) count,
        materialCode
        FROM
yuxiao authored
30
        snapshot_inventory_detail  where 1 = 1
31
32
33
        <if test="materialCode != null">
            and materialCode = #{materialCode}
        </if>
yuxiao authored
34
35
        GROUP BY DATE_FORMAT( created, '%Y-%m' )
        ) t on t.created = a.created
36
37
    </select>
</mapper>