SQL-muotoilija
Muotoile ja korosta SQL-kyselyjä dialektikohtaisilla asetuksilla
Murre
Avainsanat
Sisennys
Tyyli
AND/OR
Syöte
Tuloste
Muotoiltu SQL ilmestyy tähän...
Esimerkit
| Type | SQL | Käytä |
|---|---|---|
| SELECT | SELECT u.id,u.name,u.email,o.total FROM users u INNER JOIN orders o ON o.user_id=u.id WHERE u.active=1 AND o.total>100 ORDER BY o.total DESC LIMIT 20 | |
| GROUP BY | select department,count(*) as headcount,avg(salary) as avg_salary from employees where hire_date>'2020-01-01' group by department having count(*)>5 order by avg_salary desc | |
| INSERT | INSERT INTO products(name,price,category_id,in_stock) VALUES('Widget',9.99,3,true),('Gadget',24.99,3,false) | |
| UPDATE | UPDATE orders SET status='shipped',shipped_at=NOW(),tracking_number='TRK123' WHERE id=42 AND status='pending' | |
| Subquery | SELECT name,salary FROM employees WHERE salary>(SELECT AVG(salary) FROM employees WHERE department='Engineering') | |
| CTE | WITH monthly_sales AS(SELECT DATE_TRUNC('month',created_at) AS month,SUM(amount) AS total FROM sales GROUP BY 1) SELECT month,total,LAG(total) OVER(ORDER BY month) AS prev_total FROM monthly_sales |