SELECT c.item_midclsno as item_clsno_second, (select item_clsname from t_bd_item_cls where item_clsno = c.item_midclsno ) as item_clsname, sum(a.sale_qty), sum(a.sale_amt), sum(a.ret_qty), sum(a.ret_amt), sum(a.giv_qty), sum(a.giv_amt) FROM t_rm_daysum a, t_bd_item_cls b, (select substring(item_clsno, 1, 2*convert(int,(select sys_var_value from t_sys_system where sys_var_id = 'gl_itm_cls_nolen'))) as item_midclsno,* from t_bd_item_info) c WHERE b.item_clsno = c.item_midclsno and ( a.item_no = c.item_no ) and ( a.oper_date BETWEEN '2022-01-01' AND '2022-11-30' ) AND ( c.item_clsno like '%' ) and ( a.branch_no like '%' ) and ( a.supcust_no like '%' ) and ( b.item_flag = '0' ) GROUP BY item_midclsno |