z-매입집계표.sql 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. -- 전월 재고 --
  2. insert into dbt_list_sum
  3. ( created_on, list_token, h_id, id, c1, c2, c3,
  4. d1, d2, d3, d4, d5,
  5. c4, c5, order_by )
  6. select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
  7. bal_qty, 0, 0, 0, 0,
  8. igroup_name, igroup_code, item_code
  9. from ( select id, item_code, item_name, sub_name, igroup_id
  10. from dbr_item as itm
  11. where item_code between '!' and '駾'
  12. and isnt_stkio = '0' and is_material = '0'
  13. ) as mx
  14. inner join ( select item_id, bal_qty
  15. from dbr_bal_item
  16. where yyyy_mm = _prev_month('20230201') and storage_id = 1
  17. ) as bal on mx.id = bal.item_id
  18. inner join ( select id, igroup_code, igroup_name
  19. from dbr_igroup
  20. where igroup_code between '!' and '駾'
  21. ) as igr on mx.igroup_id = igr.id
  22. order by item_code asc;
  23. -- 당월 수불 합계 --
  24. insert into dbt_list_sum
  25. ( created_on, list_token, h_id, id, c1, c2, c3,
  26. d1, d2, d3,
  27. d4, d5,
  28. c4, c5, order_by )
  29. select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
  30. 0, sum(io_qty*cast((stock_status+1)/2 as int)), sum(io_qty*cast(-1*(stock_status-1)/2 as int)),
  31. 0, sum(io_qty*badstk_status),
  32. igroup_name, igroup_code, item_code
  33. from ( select id, item_code, item_name, sub_name, igroup_id
  34. from dbr_item as itm
  35. where item_code between '!' and '駾'
  36. and isnt_stkio = '0' and is_material = '0'
  37. ) as mx
  38. inner join ( select item_id, io_qty, stock_status, badstk_status
  39. from dbr_stock_io as stk
  40. inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
  41. where io_date between '20230201' and '20230231'
  42. and storage_id = 1
  43. ) as stk on mx.id = stk.item_id
  44. inner join ( select id, igroup_code, igroup_name
  45. from dbr_igroup
  46. where igroup_code between '!' and '駾'
  47. ) as igr on mx.igroup_id = igr.id
  48. group by stk.item_id
  49. order by item_code asc;
  50. -- dbt_list_type1 으로 집계 --
  51. insert into dbt_list_type1
  52. ( created_on, list_token, h_id, id, c1, c2, c3,
  53. d1, d2, d3, d4, d5,
  54. c4, c5, order_by)
  55. select min(unix_timestamp()), min('a'), min(id), min(id), min(c1), min(c2), min(c2),
  56. sum(d1),
  57. sum(d2),
  58. sum(d3),
  59. sum(d1) + sum(d2) - sum(d3),
  60. sum(d5),
  61. min(c4), min(c5), min(order_by)
  62. from dbt_list_sum as mx
  63. where list_token = 'a'
  64. group by mx.id
  65. having min(mx.id) is not null
  66. order by order_by asc;
  67. =======
  68. =======
  69. >>>>>>> 62bdebd054e19dd2c2ce53384ce4fe759d13dd29
  70. insert into dbt_list_type1
  71. ( created_on, list_token, h_id, id, c1, c2, c3,
  72. d1, d2, d3, d4, d5,
  73. c4, c5 )
  74. select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
  75. bal_qty, 0, 0, 0, 0,
  76. igroup_name, igroup_code
  77. <<<<<<< HEAD
  78. =======
  79. from ( select id, item_code, item_name, sub_name, igroup_id
  80. from dbr_item as itm
  81. where itm.item_code between '!' and '駾'
  82. and ( isnt_stkio = '0' or is_material = '0' )
  83. ) as mx
  84. inner join (
  85. select item_id, bal_qty
  86. from dbr_bal_item
  87. where yyyy_mm = _prev_month('20230201') and storage_id = 1
  88. ) as last_mbal on last_mbal.item_id = mx.id
  89. inner join (
  90. select id, igroup_code, igroup_name from dbr_igroup as igr
  91. where igr.igroup_code between '!' and '駾'
  92. ) as igr on igr.id = mx.igroup_id
  93. order by item_code asc;
  94. -- 당월 수불합계 --
  95. insert into dbt_list_type1
  96. ( created_on, list_token, h_id, id, c1, c2, c3,
  97. d1, d2, d3, d4, d5,
  98. c4, c5 )
  99. select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
  100. 0, sum(io_qty*cast((stock_status+1)/2 as int)), sum(io_qty*cast(-1*(stock_status-1)/2 as int)), 0,
  101. sum(io_qty*badstk_status),
  102. igroup_name, igroup_code
  103. from ( select id, item_code, item_name, sub_name, igroup_id
  104. from dbr_item as itm
  105. where itm.item_code between '!' and '駾'
  106. and ( isnt_stkio = '0' or is_material = '0' )
  107. ) as mx
  108. inner join ( select item_id, deal_type_id, io_qty
  109. from dbr_stock_io
  110. where io_date between '20230201' and '20230231'
  111. and storage_id = 1
  112. ) as stk on stk.item_id = mx.id
  113. inner join ( select id, igroup_code, igroup_name from dbr_igroup as igr
  114. where igr.igroup_code between '!' and '駾'
  115. ) as igr on igr.id = mx.igroup_id
  116. inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
  117. order by item_code asc;
  118. from ( select id, item_code, item_name, sub_name, igroup_id
  119. from dbr_item as itm
  120. where itm.item_code between '!' and '駾'
  121. and ( isnt_stkio = '0' or is_material = '0' )
  122. ) as mx
  123. inner join (
  124. select item_id, bal_qty
  125. from dbr_bal_item
  126. where yyyy_mm = _prev_month('20230201') and storage_id = 1
  127. ) as last_mbal on last_mbal.item_id = mx.id
  128. inner join (
  129. select id, igroup_code, igroup_name from dbr_igroup as igr
  130. where igr.igroup_code between '!' and '駾'
  131. ) as igr on igr.id = mx.igroup_id
  132. order by item_code asc;
  133. -- 당월 수불합계 --
  134. insert into dbt_list_type1
  135. ( created_on, list_token, h_id, id, c1, c2, c3,
  136. d1, d2, d3, d4, d5,
  137. c4, c5 )
  138. select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
  139. 0, sum(io_qty*cast((stock_status+1)/2 as int)), sum(io_qty*cast(-1*(stock_status-1)/2 as int)), 0,
  140. sum(io_qty*badstk_status),
  141. igroup_name, igroup_code
  142. from ( select id, item_code, item_name, sub_name, igroup_id
  143. from dbr_item as itm
  144. where itm.item_code between '!' and '駾'
  145. and ( isnt_stkio = '0' or is_material = '0' )
  146. ) as mx
  147. inner join ( select item_id, deal_type_id, io_qty
  148. from dbr_stock_io
  149. where io_date between '20230201' and '20230231'
  150. and storage_id = 1
  151. ) as stk on stk.item_id = mx.id
  152. inner join ( select id, igroup_code, igroup_name from dbr_igroup as igr
  153. where igr.igroup_code between '!' and '駾'
  154. ) as igr on igr.id = mx.igroup_id
  155. inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
  156. order by item_code asc;
  157. >>>>>>> a12a75b5e2b8584ff6dcd2fe635e566613dfec2c