SELECT work.work_machine_brand,
       work.work_machine_model,
       work.work_machine_sn,
#        maint.work_machine_maintenance_id,
       maint.work_machine_id,
#        maint.record_typology,
#        maint.record_sub_typology,
#        maint.record_relations,
#        maint.record_status,
#        maint.record_locked,
#        maint.record_uuid,
#        maint.record_code,
#        maint.record_list_name,

       maint.work_machine_maintenance_name as operazione,
       maint.work_machine_maintenance_place as posizione,
#        maint.work_machine_maintenance_amount,
       maint.work_machine_maintenance_text as info,
#        maint.file_name1,
#        maint.file_description1,
#        maint.file_name2,
#        maint.file_description2,
#        maint.file_name3,
#        maint.file_description3,
#        maint.file_name4,
#        maint.file_description4,
#        maint.record_control_code,
#        maint.record_control_fields,
       DATE(maint.work_machine_maintenance_date) as data_manutenzione,
       DATE(maint.end_at) as scadenza
#        maint.created_by,
#        maint.updated_by,
#        maint.deleted_by,
#        maint.created_at,
#        maint.updated_at

FROM work_machine_maintenances as maint
         left join work_machines as work on maint.work_machine_id = work.work_machine_id
WHERE maint.end_at <> 'NULL'
  AND maint.end_at
    BETWEEN NOW() and DATE_ADD(NOW(), INTERVAL 5 MONTH)
ORDER BY work_machine_id, work_machine_brand asc