Poprawa wydajności zapytań w SQL Server
Dean Smith
Founder, Atamai Analytics



Select ps.Team, count(p.PlayerName)
As NonNthAmerPlayers from
PlayerStats ps inner
join (select PlayerName FROM Players
WHERE Country <> 'USA' Or Country
<> 'Canada' )
p on p.PlayerName = ps.PlayerName
group BY ps.Team
having Count(p.PlayerName)
>=24 Order by NonNthAmerPlayers desc
| Team | NonNthAmerPlayers |
|---|---|
| HOU | 24 |
| LAL | 24 |
| MEM | 24 |
| MIL | 24 |
SELECT, FROM, WHERE itp.ONAND/ORASPrzed
Select ps.Team, count(p.PlayerName)
As NonNthAmerPlayers from
PlayerStats ps inner
join (select PlayerName FROM Players
WHERE Country <> 'USA' Or Country
<> 'Canada' )
p on p.PlayerName = ps.PlayerName
group BY ps.Team
having Count(p.PlayerName)
>=24 Order by NonNthAmerPlayers desc
Po
SELECT ps.Team,
COUNT(p.PlayerName) NonNthAmerPlayers
FROM PlayerStats ps
INNER JOIN
(SELECT PlayerName
FROM Players
WHERE Country <> 'USA'
OR Country <> 'Canada' ) p
ON p.PlayerName = ps.PlayerName
GROUP BY ps.Team
HAVING COUNT(p.PlayerName) >=24
ORDER BY NonNthAmerPlayers DESC;
/* Returns a list of NBA teams with 24 or more non-North American players on the team roster. */SELECT ps.Team, COUNT(p.PlayerName) NonNthAmerPlayers FROM PlayerStats ps INNER JOIN (SELECT PlayerName FROM Players WHERE Country <> 'USA' OR Country <> 'Canada' ) p ON p.PlayerName = ps.PlayerName GROUP BY ps.Team HAVING COUNT(p.PlayerName) >=24 ORDER BY NonNthAmerPlayers DESC;
Użyj /* i */, aby zakomentować blok kodu lub tekstu
/* Returns a list of NBA teams with 24 or more non-North American players on the team roster. */SELECT ps.Team, COUNT(p.PlayerName) NonNthAmerPlayers FROM PlayerStats ps INNER JOIN (SELECT PlayerName FROM Players WHERE Country <> 'USA' OR Country <> 'Canada' ) p ON p.PlayerName = ps.PlayerName GROUP BY ps.Team HAVING COUNT(p.PlayerName) >=24 ORDER BY NonNthAmerPlayers DESC;
Użyj /* i */, aby zakomentować blok kodu lub tekstu
| Team | NonNthAmerPlayers |
|---|---|
| HOU | 24 |
| LAL | 24 |
| MEM | 24 |
| MIL | 24 |
Użyj --, aby zakomentować pojedynczą linię kodu lub tekstu
SELECT ps.Team,
COUNT(p.PlayerName) NonNthAmerPlayers
FROM PlayerStats ps
INNER JOIN
(SELECT PlayerName
FROM Players
WHERE Country <> 'USA'
OR Country <> 'Canada' ) p
ON p.PlayerName = ps.PlayerName
GROUP BY ps.Team
HAVING COUNT(p.PlayerName) >=24
ORDER BY NonNthAmerPlayers DESC;
Użyj --, aby zakomentować pojedynczą linię kodu lub tekstu
SELECT ps.Team,
COUNT(p.PlayerName) NonNthAmerPlayers -- Count of players
FROM PlayerStats ps
INNER JOIN
(SELECT PlayerName
FROM Players
WHERE Country <> 'USA'
OR Country <> 'Canada' ) p -- Indented qub-suery
ON p.PlayerName = ps.PlayerName
GROUP BY ps.Team
HAVING COUNT(p.PlayerName) >=24
ORDER BY NonNthAmerPlayers DESC;
Użyj --, aby zakomentować pojedynczą linię kodu lub tekstu
SELECT ps.Team,
COUNT(p.PlayerName) NonNthAmerPlayers -- Count of players
FROM PlayerStats ps
-- Inner join starts here
INNER JOIN
(SELECT PlayerName
FROM Players
WHERE Country <> 'USA'
OR Country <> 'Canada' ) p -- Indented qub-suery
ON p.PlayerName = ps.PlayerName
GROUP BY ps.Team
HAVING COUNT(p.PlayerName) >=24
-- Remove the ORDER BY, it is not required
ORDER BY NonNthAmerPlayers DESC;
INNER JOIN
ORDER BYUżyj --, aby zakomentować pojedynczą linię kodu lub tekstu
SELECT ps.Team,
COUNT(p.PlayerName) NonNthAmerPlayers -- Count of players
FROM PlayerStats ps
-- Inner join starts here
INNER JOIN
(SELECT PlayerName
FROM Players
WHERE Country <> 'USA'
OR Country <> 'Canada' ) p -- Indented qub-suery
ON p.PlayerName = ps.PlayerName
GROUP BY ps.Team
HAVING COUNT(p.PlayerName) >=24;
-- Remove the ORDER BY, it is not required
-- ORDER BY NonNthAmerPlayers DESC
ORDER BYPoprawa wydajności zapytań w SQL Server