Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 티스토리챌린지
- 중복 컬럼
- HAVING
- r/2
- %_%
- order by
- join
- ERP
- over()
- spa
- desc
- 오블완
- SAP HANA
- between
- CSV
- SERVICE_KEY_IS_NOT_REGISTERED_ERROR
- S/4 HANA
- Where
- R/3
- dense_rank()
- DateDiff
- asc
- union
- stratascratch
- json
- limit
- group by
- left join
- 공공데이터
- SQL
Archives
- Today
- Total
RE:cord
[SQL] Finding the Nth Highest Values (JOIN/ORDER BY /LIMIT/DENSE_RANK () OVER) 본문
SQL
[SQL] Finding the Nth Highest Values (JOIN/ORDER BY /LIMIT/DENSE_RANK () OVER)
beie 2024. 11. 30. 18:53<1>
-- 1. join / 2. select
SELECT worker_title, salary
FROM worker JOIN title ON worker.worker_id=title.worker_ref_id
WHERE salary >= (SELECT MAX(salary) FROM worker)
<2>
-- using LIMIT
SELECT *
FROM worker
WHERE salary >= (
SELECT DISTINCT salary
FROM worker
ORDER BY salary DESC
LIMIT 4, 1);
-- using DENSE_RANK
SELECT first_name, salary, salary_rank
FROM (SELECT first_name,salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM worker) worker_order
WHERE salary_rank <= 5;
* LIMIT
- LIMIT n: Retrieves the first n rows.
- LIMIT offset, n: Skips the first offset rows and retrieves the next n rows.
- LIMIT cannot handle duplicate values effectively on its own, so it is often used in subqueries for better control.
'SQL' 카테고리의 다른 글
[SQL] Analyzing User Retention (유저 리텐션 분석) (DATEDIFF / BETWEEN AND / HAVING) (0) | 2024.12.04 |
---|---|
[SQL] Search for Data Containing Keywords (WHERE LIKE '%A%') (0) | 2024.12.03 |
[SQL] Count the number of group (GROUP BY / JOIN / LEFT JOIN / SUM) (2) | 2024.11.27 |
[SQL] Find the Nth group (DENSE_RANK / OVER / SUBQUERY) (0) | 2024.11.24 |
[SQL] AVG / GROUP BY / ORDER BY DESC (2) | 2024.11.22 |