z-매입집계표.sql 5.1 KB

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