SELECT
e.equipment_running,
e.equipment_code,
e.company_code,
e.equipment_category_code,
ec.equipment_category_name,
e.equipment_group_code,
eg.equipment_group_name,
e.equipment_type_code,
et.equipment_type_name,
e.equipment_name,
e.tag_number,
e.brand_code,
b.brand_name,
e.serial_number,
e.last_receive_price,
e.point_order,
e.warehouse_code,
w.warehouse_name,
e.location_code,
u.unit_description AS receive_unit_desc,
l.location_name,
e.active,
e.create_date,
e.create_by,
e.update_date,
e.update_by,
e.equipment_number,
ifnull(se.equipment_code, 0) AS se_equipment_code,
ifnull(((sum(se.balance_quantity) + sum(se.receive_quantity)) - sum(se.draw_quantity)), 0) AS sum_remain_quan,
e.point_maximum
FROM
equipment e
INNER JOIN equipment_category ec ON (e.equipment_category_code = ec.equipment_category_code)
AND (e.company_code = ec.company_code)
INNER JOIN equipment_group eg ON (e.equipment_group_code = eg.equipment_group_code)
AND (e.company_code = eg.company_code)
INNER JOIN equipment_type et ON (e.equipment_type_code = et.equipment_type_code)
AND (e.company_code = et.company_code)
INNER JOIN brand b ON (e.brand_code = b.brand_code)
AND (e.company_code = b.company_code)
INNER JOIN warehouse w ON (e.warehouse_code = w.warehouse_code)
AND (e.company_code = w.company_code)
INNER JOIN location l ON (e.location_code = l.location_code)
AND (e.company_code = l.company_code)
INNER JOIN unit u ON (e.receive_unit_code = u.unit_code)
AND (e.company_code = u.company_code)
LEFT OUTER JOIN stock_equipment se ON (se.equipment_code = e.equipment_code)
AND (e.company_code = se.company_code)
WHERE
ifnull(se.equipment_code, 0) = _tis620'0'
GROUP BY
e.equipment_code