Notice
Recent Posts
Recent Comments
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 |
Tags
- 재귀쿼리
- 표본분포
- limit
- 신뢰구간
- rrule
- pivot table
- dateofmonth
- lambda
- 태블로
- 표분편차
- 프로그래머스
- datediff
- calesce
- 데이터 리터러시
- DATE_FORMAT
- truncate
- merge
- concat
- 재퀴쿼리
- 표준오차
- curdate
- tableau
- 레이더차트
- split
- floor
- 정규분포
- 모집단
- join
- Recursive
- python
Archives
- Today
- Total
반응형
hyezdata 님의 블로그
Exchange Seats 본문
# 연속된 id 둘씩 순서 바꾸기
# 햑생 수 홀수면 마지막 학생은 바꾸기x
# id 오름차순
select case when id%2=0 then id-1
when (id%2!=0 and id=(select max(id) from seat)) then id
when id%2!=0 then id+1
end id,
student
from seat
order by id
댓글에 적어놓은 힌트 참고 함
1] You can use a CASE statement to handle swapping between adjacent seats. The key is
to check whether the id is odd or even:
2] If the id is odd, swap the student with the one in the next seat (id + 1).
3] If the id is even, swap the student with the one in the previous seat (id - 1).
Exchange Seats - LeetCode
Can you solve this real interview question? Exchange Seats - Table: Seat +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | student | varchar | +-------------+---------+ id is the primary key (unique value) column for
leetcode.com
728x90
반응형
'코딩테스트' 카테고리의 다른 글
| Swap Sex of Employees (0) | 2026.05.30 |
|---|---|
| Biggest Single Number (0) | 2026.05.25 |
| Triangle Judgement (0) | 2026.05.25 |
| Sales Person (0) | 2026.05.25 |
| Customer Placing the Largest Number of Orders (0) | 2026.05.22 |