GROUP BY FLOOR(TIME_TO_SEC(TIMEDIFF(`start_date`, '2015-12-01'))/2/24/60/60)
SELECT `p`.`id`
FROM `product` AS `p`
JOIN `product_color` AS `pc1` ON `pc1`.`product_id` = `p`.`id`
JOIN `color` AS `c1` ON `c1`.`id` = `pc1`.`color_id`
AND `c1`.`name` = 'black'
JOIN `product_size` AS `ps1` ON `ps1`.`product_id` = `p`.`id`
JOIN `size` AS `s1` ON `s1`.`id` = `ps1`.`size_is`
AND `s1`.`name` = 'S'
JOIN `product_size` AS `ps2` ON `ps2`.`product_id` = `p`.`id`
JOIN `size` AS `s2` ON `s2`.`id` = `ps2`.`size_is`
AND `s2`.`name` = 'M'
JOIN `product_size` AS `ps3` ON `ps3`.`product_id` = `p`.`id`
JOIN `size` AS `s3` ON `s3`.`id` = `ps3`.`size_is`
AND `s3`.`name` = 'L'
DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements.
UID = RID - BASE_RID + LOW_RANGE_ID
idmap config MOVAVI : base_rid = 1000
idmap config MOVAVI : range = 10000-28999