SELECT
CONCAT(
'UPDATE free_for_demo_orders SET product_id=',
product_id,
',order_created_time=',
'"',
TIMESTAMPADD(HOUR, 8, sales_order.created_at),
'" WHERE order_id=',
entity_id,
';'
),
`entity_id`,
customer_id,
`customer_email`,
quote_id,
sales_order.store_id,
product_id,
TIMESTAMPADD(HOUR, 8, sales_order.created_at),
TIMESTAMPADD(HOUR, 8, sales_order.created_at)
FROM
`sales_flat_order` AS sales_order
LEFT JOIN `sales_flat_order_item` ON entity_id=order_id
WHERE STATUS <> 'canceled' AND grand_total=10 AND price = 0