SELECT
	sa.id as id,
	NULL as accept_order_id,
	NULL as sample_id,
	1 as rev_number,
	sa.input_date as input_date,
	sa.sample_date as target_date,
	sa.op_date as operate_date,
	35 as user_id,
	19 as section_id,
	2 as sample_trigger_code,
	sa.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,
	sa.dealer_id as customer_id,
	1 as supplier_id,
	IF(sa.total_quantity<0,0,1) as sign_type_code,
	sa.close_flag_id as state_code,
	sa.sample_note as note,
	0 as invalid_flag_code,
	NULL as deleted_at,
	NOW() as created_at,
	NOW() as updated_at
FROM samples as sa
LEFT JOIN staffs as st
	ON sa.staff_id = st.id
LEFT JOIN user_positions as up
	ON st.user_position_id = up.id
LEFT JOIN local_areas as la
	ON sa.local_area_id = la.id
INTO OUTFILE "/tmp/samples.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';