Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT REVERSE(stores.`name`) AS `reversed_name`, CONCAT(UPPER(towns.`name`),'-', addresses.`name` ) AS `full_address`,
- COUNT(employees.`id`) AS `employees_count`, ROUND(MIN(products.`price`),2 )AS `min_price`,COUNT(products.`id`) AS `product_count`, MAX(DATE_FORMAT(pictures.`added_on`, '%D-%b-%Y')) as `newest_pic`
- FROM towns
- LEFT JOIN addresses ON addresses.`town_id` = towns.`id`
- LEFT JOIN stores ON stores.`address_id` = addresses.`id`
- LEFT JOIN employees ON employees.`store_id` = stores.`id` LEFT JOIN products_stores ON products_stores.`store_id` = stores.`id`
- LEFT JOIN products ON products_stores.`product_id` = products.`id`
- LEFT JOIN pictures ON pictures.`id` = products.`picture_id`
- GROUP BY towns.`name`, stores.`id`,addresses.`name`
- HAVING `min_price` > 10
- ORDER BY `reversed_name`, `min_price`;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement