Améliorer la performance des requêtes dans SQL Server
Dean Smith
Founder, Atamai Analytics
SELECT *
FROM PlayerStats
WHERE Position = 'SG'

SELECT *
FROM PlayerStats
WHERE Position = 'SG'

SELECT PlayerName,
Team,
(DRebound+ORebound) AS TotalRebounds
FROM PlayerStats
WHERE TotalRebounds >= 1000
ORDER BY TotalRebounds DESC;
-- ERROR
Invalid column name 'TotalRebounds'.
SELECT PlayerName,
Team,
TotalRebounds
FROM
-- Début de la sous-requête tr
(SELECT PlayerName, Team,
(DRebound+ORebound) AS TotalRebounds
FROM PlayerStats) tr
WHERE TotalRebounds >= 1000 -- créé dans la sous-requête
ORDER BY TotalRebounds DESC;
SELECT PlayerName,
Team,
TotalRebounds
FROM
-- Début de la sous-requête tr
(SELECT PlayerName, Team,
(DRebound+ORebound) AS TotalRebounds
FROM PlayerStats) tr
WHERE TotalRebounds >= 1000 -- créé dans la sous-requête
ORDER BY TotalRebounds DESC;
| PlayerName | Team | TotalRebounds |
|---|---|---|
| Andre Drummond | DET | 1247 |
| DeAndre Jordan | LAC | 1171 |
| Karl-Anthony Towns | MIN | 1012 |
| Dwight Howard | CHO | 1012 |
SELECT PlayerName,
Team,
(DRebound+ORebound) AS TotalRebounds
FROM PlayerStats
WHERE (DRebound+ORebound) >= 1000
ORDER BY TotalRebounds DESC;
| PlayerName | Team | TotalRebounds |
|---|---|---|
| Andre Drummond | DET | 1247 |
| DeAndre Jordan | LAC | 1171 |
| Karl-Anthony Towns | MIN | 1012 |
| Dwight Howard | CHO | 1012 |
SELECT PlayerName, College, DraftYear
FROM Players
WHERE UPPER(LEFT(College,7)) = 'GEORGIA';
-- utilisation inutile de fonctions
-- sur une colonne filtrée
| PlayerName | College | DraftYear |
|---|---|---|
| Damien Wilkins | Georgia | |
| Derrick Favors | Georgia Tech | 2010 |
| Iman Shumpert | Georgia Tech | 2011 |
| R.J. Hunter | Georgia State | 2015 |
| ... | ... | ... |
SELECT PlayerName, College, DraftYear
FROM Players
-- Aucun calcul ni fonction
WHERE College like 'Georgia%';
| PlayerName | College | DraftYear |
|---|---|---|
| Damien Wilkins | Georgia | |
| Derrick Favors | Georgia Tech | 2010 |
| Iman Shumpert | Georgia Tech | 2011 |
| R.J. Hunter | Georgia State | 2015 |
| ... | ... | ... |
Améliorer la performance des requêtes dans SQL Server