Code :
SELECT a.products_model , MAX(CASE WHEN a.seq = 1 THEN a.products_images ELSE NULL END) IMG1 , MAX(CASE WHEN a.seq = 2 THEN a.products_images ELSE NULL END) IMG2 , MAX(CASE WHEN a.seq = 3 THEN a.products_images ELSE NULL END) IMG3 , MAX(CASE WHEN a.seq = 4 THEN a.products_images ELSE NULL END) IMG4 , MAX(CASE WHEN a.seq = 5 THEN a.products_images ELSE NULL END) IMG5 , MAX(CASE WHEN a.seq = 6 THEN a.products_images ELSE NULL END) IMG6 , MAX(CASE WHEN a.seq = 7 THEN a.products_images ELSE NULL END) IMG7 , MAX(CASE WHEN a.seq = 8 THEN a.products_images ELSE NULL END) IMG8 , MAX(CASE WHEN a.seq = 9 THEN a.products_images ELSE NULL END) IMG9 , MAX(CASE WHEN a.seq = 10 THEN a.products_images ELSE NULL END) IMG10 FROM ( SELECT products.products_model , products_images.products_images , ROW_NUMBER() OVER (PARTITION BY products.products_model ORDER BY products.products_model) seq FROM products JOIN products_images ON products.products_id=products_images.products_id ) a GROUP BY a.products_model
|