SQLZOO 정답: 9 - Windows 기능
7748 단어 SQLZOO
SELECT lastName, party, votes
FROM ge
WHERE constituency = 'S14000024' AND yr = 2017
ORDER BY votes DESC
SELECT party, votes,
RANK() OVER (ORDER BY votes DESC) as posn
FROM ge
WHERE constituency = 'S14000024' AND yr = 2017
ORDER BY party
SELECT yr,party, votes,
RANK() OVER (PARTITION BY yr ORDER BY votes DESC) as posn
FROM ge
WHERE constituency = 'S14000021'
ORDER BY party,yr
SELECT constituency,party, votes,
RANK() OVER (PARTITION BY constituency ORDER BY votes DESC) as posn
FROM ge
WHERE constituency BETWEEN 'S14000021' AND 'S14000026'
AND yr = 2017
ORDER BY posn,constituency
SELECT constituency,party FROM
(SELECT constituency,party, votes,
RANK() OVER (PARTITION BY constituency ORDER BY votes DESC) as posn
FROM ge
WHERE constituency BETWEEN 'S14000021' AND 'S14000026'
AND yr = 2017) RK
WHERE RK.posn=1
SELECT party,COUNT(*) FROM (
SELECT constituency,party, votes,
RANK() OVER (PARTITION BY constituency ORDER BY votes DESC) as posn
FROM ge
WHERE constituency LIKE 'S%'
AND yr = 2017) rk
WHERE rk.posn=1
GROUP BY rk.party
최근에 sql를 쓰고 있기 때문에 인터넷에서 답을 찾지 못하고 이 글을 썼습니다. 그 중에서 sql가 가장 좋은 것은 아닐 수도 있지만 결과는 문제없습니다.이것은 CSDN을 사용한 이래 첫 번째 CSDN 문장입니다. 여러분의 지적을 환영합니다.만약 여러분께 더 좋은 ql가 있다면, 아낌없이 메시지를 남겨 주십시오.