InventoryChangesMapper.xml
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?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">
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 <= #{endTime}
order by created ) a left join
(SELECT
DATE_FORMAT( created, '%Y-%m' ) created,
sum( qty ) count,
materialCode
FROM
snapshot_inventory_detail where 1 = 1
<if test="materialCode != null">
and materialCode = #{materialCode}
</if>
GROUP BY DATE_FORMAT( created, '%Y-%m' )
) t on t.created = a.created
</select>
</mapper>