| 279 | == Прикажи го продуктот за кој постојат најмал број направени нарачки. |
| 280 | {{{ |
| 281 | |
| 282 | WITH product_orders_count AS ( |
| 283 | SELECT |
| 284 | p.id AS product_id, |
| 285 | p.name AS product_name, |
| 286 | p.description AS product_description, |
| 287 | p.price AS product_price, |
| 288 | COALESCE(COUNT(o.id), 0) AS orders_count |
| 289 | FROM |
| 290 | project.products p |
| 291 | LEFT JOIN |
| 292 | project.product_are_made_orders pamo ON p.id = pamo.id_products |
| 293 | LEFT JOIN |
| 294 | project.orders o ON pamo.id_orders = o.id |
| 295 | GROUP BY |
| 296 | p.id, p.name, p.description, p.price |
| 297 | ) |
| 298 | SELECT |
| 299 | product_id, |
| 300 | product_name, |
| 301 | product_description, |
| 302 | product_price, |
| 303 | orders_count |
| 304 | FROM |
| 305 | product_orders_count |
| 306 | WHERE |
| 307 | orders_count = ( |
| 308 | SELECT MIN(orders_count) |
| 309 | FROM product_orders_count |
| 310 | ); |
| 311 | |
| 312 | }}} |