SELECT
	adj.id as id,
	1 as rev_number,
	adj.adjustment_date as input_date,
	adj.adjustment_date as target_date,
	35 as user_id,
	19 as section_id,
	adj.hospital_id as warehouse_id,
	st.user_position_id as user_position_id,
	up.user_id as sales_user_id,
	la.sales_area_id as sales_area_id,
	up.section_id as sales_section_id,
	adj.dealer_id as customer_id,
	1 as supplier_id,
	adj.close_flag_id as state_code,
	adj.adjustment_note as note,
	0 as invalid_flag_code,
	NULL as deleted_at,
	NOW() as created_at,
	NOW() as updated_at
FROM adjustments as adj
LEFT JOIN staffs as st
	ON adj.staff_id = st.id
LEFT JOIN user_positions as up
	ON st.user_position_id = up.id
LEFT JOIN local_areas as la
	ON adj.local_area_id = la.id
INTO OUTFILE "/tmp/adjustments.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';