๋ฌธ์ Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped. Return the result table ordered by id in ascending order. ๋ฌธ์ ์์ฝ ์ฐ์๋ seatid์ธ ํ์๋ค์ ์๋ฆฌ๋ฅผ ๋ฐ๊ฟ๋ผ ํ์ ์๊ฐ ํ์๋ฉด, ๋ง์ง๋ง ํ์์ ๋ฐ๊พธ์ง ์๋๋ค. id ๊ธฐ์ค ์ค๋ฆ์ฐจ์ ์ ๋ ฌํด ์ถ์ถํ๋ผ ํ์ด 1. id๊ฐ ์ง์๋ฉด -1, ํ์๋ฉด +1 ๋ถ์ฌ 2. ํ์ ์๊ฐ ํ์๋ฉด, ๋ง์ง๋ง ํ์id์ 1 ๋ํด์ง id๊ฐ์ ๋ถ์ฌ๋๋ ์ด๋ฆ์ null 3. CASE WHEN THEN ์๋ธ์ฟผ๋ฆฌ ์ฌ์ฉ WITH t..
๋ฌธ์ Write a solution to find the prices of all products on 2019-08-16. Assume the price of all products before any change is 10. Return the result table in any order. The result format is in the following example. ๋ฌธ์ ์์ฝ 2019-08-16 ์ด ๋ , ๋ชจ๋ ์ ํ์ ๊ฐ๊ฒฉ์ ์ถ์ถํ๋ผ. ๋จ, ๋ชจ๋ ๊ฐ๊ฒฉ์ ๋ณ๊ฒฝ ์ด์ ๊ฐ๊ฒฉ์ 10์ด๋ผ๊ณ ๊ฐ์ ํ์ด 1. change_date๊ฐ '2019-08-16' ์ด์ ์ธ ์ ํ๋ค๋ง ์ถ๋ฆฐ ํ, ๊ฑฐ๊ธฐ์ MAX(change_date)์ ๊ฐ๊ฒฉ ์ถ์ถ 2. ๋๋จธ์ง change_date๊ฐ '2019-08-16' ์ดํ์ธ ์ ํ๋ค๋ง ..
๋ฌธ์ Write a solution to delete all duplicate emails, keeping only one unique email with the smallest id. For SQL users, please note that you are supposed to write a DELETE statement and not a SELECT one. ๋ฌธ์ ์์ฝ ์ด๋ฉ์ผ์ด ๊ฐ์ ๊ฒ๋ค ์ค, ์์ด๋๊ฐ ์์ ๊ฒ์ ๋จ๊ธฐ๊ณ ํฐ ๊ฒ์ ์ง์๋ผ ํ์ด DELETE p1 FROM person p1, person p2 WHERE p1.email = p2.email AND p1.id > p2.id : ๊ฐ์ ํ ์ด๋ธ์ CROSS JOIN ํ, ์ด๋ฉ์ผ์ด ๊ฐ์ ๊ฒ๋ค ์ค ์์ด๋๊ฐ ํฐ ๊ฒ์ ์ง์ฐ๋๋ก ์กฐ๊ฑด์ ์์ฑํด์ค๋ค.
๋ฌธ์ Write a solution to calculate the number of bank accounts for each salary category. The salary categories are: "Low Salary": All the salaries strictly less than $20000. "Average Salary": All the salaries in the inclusive range [$20000, $50000]. "High Salary": All the salaries strictly greater than $50000. The result table must contain all three categories. If there are no accounts in a catego..