Beginning stocks for the recent number of surplus items before the start of the search time
Figure 1 yet search
When checking the search, more of a beginning inventory as
Click on the query, the number corresponding to the beginning changed, as described above
Use mybatis query
At first, the establishment of a database table, which is recorded as a single income, issue a change
During inquiry, according to the sum (the number of revenue), sum (issue number) to show, and according to group by name
The difficulty here, when the time interval within the search does not change the article, want to get to the nearest number of beginning stocks surplus
# Gets beginning inventory from a search start time of the last piece of data, and get away from the end of the search time of the last piece of data inventory balances. # ' 2019-12-27 22:02:01 ' to assume that the start time of the SELECT qichu .qichukucun from ( SELECT qichukucun from wuliaokucunrizhi WHERE CreateTime > ' 2019-12-27 22:02:01 ' the ORDER BY CreateTime limit . 1 ) qichu
If you want to sum the number of income and outgoing, first get to the data tuples the search time interval, then
If the data does not include some items tuple, not meet the requirements, it must be carried out to show all inventory items, as well as to demonstrate its beginning stocks
It is conceivable that since the first association table, according to a time interval table sum, the other group by name, the name of all the items can be performed, and the sum value calculated in the partial time interval
< SELECT ID = "listKucunWithRiZhi" The resultMap = "BaseResultMap" > SELECT AS mingchengguige the DISTINCT rizhi2.mingchengguige, IFNULL (rizhi1.qichukucun1,0) qichukucun, IFNULL (rizhi1.shourushuliang1,0) shourushuliang, IFNULL (rizhi1.fachushuliang1,0) fachushuliang , IFNULL (rizhi1.tuihuishuliang1,0) tuihuishuliang, IFNULL (rizhi1.jieyushuliang1,0) jieyushuliang from ( SELECT the DISTINCT (kucunrizhi.mingchengguige) AS mingchengguige, SUBSTRING_INDEX (GROUP_CONCAT (kucunrizhi.id Order by kucunrizhi.createtime desc), ',' , 1) as id, SUBSTRING_INDEX (GROUP_CONCAT (kucunrizhi.xiangmuweihu Order by kucunrizhi.createtime desc), ',' , 1) AS xiangmuweihu, substring_index(group_concat(kucunrizhi.rukukufang order by kucunrizhi.createtime desc),',',1)as rukukufang, substring_index(group_concat(kucunrizhi.dalei order by kucunrizhi.createtime desc),',',1)as dalei, substring_index(group_concat(kucunrizhi.qichukucun order by kucunrizhi.createtime),',',1)qichukucun1, sum(kucunrizhi.shourushuliang)as shourushuliang1, sum(kucunrizhi.fachushuliang)as fachushuliang1, sum(kucunrizhi.tuihuishuliang)as tuihuishuliang1, substring_index(group_concat(kucunrizhi.jieyushuliang order by kucunrizhi.createtime desc),',',1)jieyushuliang1, substring_index(group_concat(kucunrizhi.jiagongyigong order by kucunrizhi.createtime desc),',',1)as jiagongyigong, substring_index(group_concat(kucunrizhi.createtime order by kucunrizhi.createtime desc),',',1)as createtime from wuliaokucunrizhi as kucunrizhi <where> <if test="mingchengguige != null and mingchengguige != '' "> <bind name="mingchengguigePattern" value="'%'+mingchengguige+'%'"/> and kucunrizhi.mingchengguige like #{mingchengguigePattern} </if> <if test="jiagongyigong != null and jiagongyigong != '' "> and kucunrizhi.jiagongyigong = # {jiagongyigong} </if> <if test="rukukufang != null and rukukufang != '' "> and kucunrizhi.rukukufang = #{rukukufang} </if> <if test="xiangmuweihu != null and xiangmuweihu != ''"> and kucunrizhi.xiangmuweihu = #{xiangmuweihu} </if> <if test="dalei != null and dalei != '' "> and kucunrizhi.dalei = #{dalei} </if> <if test="s_btime != null"> and kucunrizhi.createtime >= #{s_btime} </if> <if test="s_etime != null"> and kucunrizhi.createtime <= date_add(#{s_etime}, interval 1 day) </if> <if test="createtime != null"> and kucunrizhi.createtime = #{createtime} </if> <if test="updatetime != null"> and kucunrizhi.updatetime = #{updatetime} </if> </where> GROUP BY kucunrizhi.mingchengguige <if test="sort == null"> ORDER BY createtime DESC </if> <if test="sort != null and sort != ''"> order by ${sort} ${order} </if>)rizhi1 right join wuliaokucunrizhi as rizhi2 on rizhi1.mingchengguige = rizhi2.mingchengguige </select>
Here, however, and can not get to a normal beginning inventory values, because of its acquisition value is based on the time interval to get, if not in the time interval, you can not return