*) 출처 https://www.hackerrank.com/challenges/the-report/problem?h_r=internal-search
SELECT CASE WHEN G.GRADE < 8 THEN NULL ELSE S.NAME END AS NAME,
G.GRADE,
S.MARKS
FROM STUDENTS AS S
INNER JOIN GRADES AS G ON S.MARKS BETWEEN G.MIN_MARK AND G.MAX_MARK
ORDER BY G.GRADE DESC, NAME , S.MARKS
*) 출처 : https://leetcode.com/problems/consecutive-numbers/
Input:
Logs table:
+----+-----+
| id | num |
+----+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 1 |
| 6 | 2 |
| 7 | 2 |
+----+-----+
Output:
+-----------------+
| ConsecutiveNums |
+-----------------+
| 1 |
+-----------------+
Explanation: 1 is the only number that appears consecutively for at least three times.
[내가 작성한 정답]
SELECT DISTINCT L.NUM as ConsecutiveNums
FROM LOGS L
INNER JOIN LOGS L2 ON L.ID = L2.ID
INNER JOIN LOGS L3 ON L.ID = L3.ID
WHERE L.NUM = L2.NUM = L3.NUM
[강의 답]
SELECT DISTINCT L.NUM AS consecutiveNUMS
FROM Logs AS L
INNER JOIN Logs AS L_NEXT ON L.ID+1 = L_NEXT.ID
INNER JOIN Logs AS L_NEXT2 ON L.ID+2 = L_NEXT2.ID
WHERE L.NUM = L_NEXT.NUM AND L.NUM =L_NEXT2.NUM