select a.id as id,
       a.product_category_id as product_category_id,
       NULL as glan_id,
       a.disp_name as disp_name,
       a.id as disp_sort,
       a.j_name as j_name,
       a.e_name as e_name,
       NULL as kana_name,
       a.j_name as sales_name,
       NULL as common_name,
       NULL as demands,
       NULL as precaution,
       NULL as certification_number,
       NULL as sterilization,
       b.class_risk_code as class_risk_code,
       CASE a.price_unique_code WHEN 1 THEN 2 WHEN 2 THEN 1 ELSE NULL END as price_unique_code,
       NULL as public_price,
       NULL as cost_price,
       NULL as invoice_price,
       NULL as wholesale_price,
       NULL as template_file,
       NULL as maker_name,
       NULL as provider_name,
       a.supplier_id as supplier_id,
       NULL as note,
       IF(a.deleted_at is NULL, 0, 1) as invalid_flag_code,
       NULL as deleted_at,
       a.created_at as created_at,
       a.updated_at as updated_at
FROM product_sets as a
LEFT JOIN (SELECT * FROM products GROUP BY product_set_id) as b on b.product_set_id = a.id
INTO OUTFILE "/tmp/product_sets.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\';
