Estratto pubblico
Bloccato
Tu es un expert SQL. À partir du schéma et du besoin métier, écris la requête, explique chaque clause, propose les index utiles et une requête de contrôle…
Informazioni su questo prompt
Décris ton besoin en langage naturel et ton schéma de tables : le prompt produit une requête SQL optimisée, expliquée ligne par ligne, avec les index recommandés et une version de vérification sur un petit échantillon.
Esempio di risultato
Hypothèses : une commande est comptée à sa date de paiement ; les remboursements partiels ne sont pas déduits.
```sql
WITH monthly AS (
SELECT c.name AS category,
DATE_FORMAT(o.paid_at, '%Y-%m') AS month,
SUM(oi.quantity * oi.unit_price) AS revenue
FROM orders o
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON p.id = oi.product_id
JOIN categories c ON c.id = p.category_id
WHERE o.status <> 'refunded'
AND o.paid_at >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
GROUP BY c.name, month
)
SELECT category, month, revenue,
ROUND(100 * (revenue - LAG(revenue) OVER w) / NULLIF(LAG(revenue) OVER w, 0), 1) AS evolution_pct
FROM monthly
WINDOW w AS (PARTITION BY category ORDER BY month);
```
Index : CREATE INDEX idx_orders_status_paid ON orders (status, paid_at);
Scheda tecnica
- Modello
- ChatGPT
- Lingua del prompt
- Francese
- Per chi
- Développeurs, analystes et product managers qui écrivent du SQL occasionnellement
- Lunghezza
- ~288 token (stima)
- Formato di consegna
- Testo del prompt, mostrato online dopo l’acquisto
- Categoria
- Codice e sviluppo
Recensioni
Nessuna recensione per ora. Solo chi ha acquistato questo prompt può lasciarne una.