전체 글502 27. JPQL - 서브 쿼리 & 타입 표현 0. 개요 - 이번 포스팅에서는 JPQL에서 SubQuery와 타입 표현에 대해 알아보자. 1. 서브 쿼리(SubQuery) a) 개념 - 서브 쿼리란, 쿼리 내부에 또 다른 쿼리를 삽입하는 형태를 말한다. - 간단한 예시를 통해서 서브 쿼리의 형태를 살펴보자. SELECT p FROM Player p WHERE p.age > (SELECT AVG(p2.age) FROM Player p2); - 이처럼 SQL과 동일하게 JPQL에서도 서브 쿼리를 사용할 수 있다. - 중요한 점은 서브 쿼리와 서브 쿼리를 포함하고 있는 쿼리는 쿼리상에서 연관 관계가 전혀 없다는 것이다. - 즉, p와 p2는 함께 사용되지 않고 독립적인 쿼리로 사용된다. - 이렇게 쿼리를 짜는 것이 서브 쿼리의 효율을 가장 잘 뽑아낼 수 .. 2022. 4. 27. LeetCode 695(Max Area of Island, java) 0. 문제 https://leetcode.com/problems/max-area-of-island/ Max Area of Island - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 이중 배열(= grid)이 주어진다. - 이중 배열의 값으로 1과 0이 주어지는데, 0은 바다를 의미하고 1은 땅을 의미한다. - 상하좌우로 연결된 1의 값을 계산하여, 그중 가장 큰 값(= 가장 큰 땅)을 반환하는 것이 문제의 핵심이다. - 이 문제는.. 2022. 4. 27. LeetCode 733(Flood Fill, java) 0. 문제 https://leetcode.com/problems/flood-fill/ Flood Fill - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 이중 배열(image)과 시작점이 되는 row(= sr)와 column(= sc) 위치, 새로운 색상(= newColor)이 주어진다. - 문제에서 제공하는 시작 위치의 값과 시작 위치를 기준으로 4방향에 존재하는 요소의 값이 동일하다면, 해당 요소의 값을 newColor로 대체하.. 2022. 4. 27. LeetCode 567(Permutation in String, java) 0. 문제 https://leetcode.com/problems/permutation-in-string/ Permutation in String - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 2개의 문자열(s1, s2)이 주어진다. - s1을 구성하는 문자의 순열 중 하나라도 s2를 구성한다면 true를 반환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 순열을 어떻게 구할 것인지에 대해서 생각해보자. -.. 2022. 4. 27. 26. JPQL - 조인 0. 개요 - JPQL에서 Join을 사용하는 방법에 대해서 알아보자. 1. Join의 종류 a) 내부 조인(inner join) - 내부 조인은 INNER JOIN 키워드를 사용한다. - 내부 조인은 JOIN의 기본 설정(= default)이다. - 그러므로 그냥 JOIN 키워드만 사용하더라도 내부 조인을 수행한다. - 내부 조인은 두 테이블을 조인할 때, 매칭되는 데이터가 존재하는 데이터만을 출력한다. - 예를 들어, 테이블 A에는 A, B, C가 있고 테이블 B에는 A, B만 존재한다고 가정해보자. - 내부 조인을 사용하는 경우, 조인 결과가 A, B만 출력된다. - 즉, C와는 매칭되는 데이터가 없으므로 C는 출력되지 않는다. - 다음 예시 코드를 보자. SELECT p FROM Player p .. 2022. 4. 26. LeetCode 3(Longest Substring Without Repeating Characters, java) 0. 문제 https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 문자열(s)이 주어진다. - 문자열을 탐색하여 중복 없이 구성된 내부 문자열 중 가장 긴 길이를 찾는 것이 핵심이다. 2. 문제 해설 a) 첫 번째 접근.. 2022. 4. 26. LeetCode 19(Remove Nth Node From End of List, java) 0. 문제 https://leetcode.com/problems/remove-nth-node-from-end-of-list/ Remove Nth Node From End of List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 연결 리스트(head)와 정수(n)가 주어진다. - 연결 리스트를 탐색하여 뒤에서부터 n번째에 위치한 노드를 삭제하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 가장 먼저 떠오르는 방.. 2022. 4. 26. LeetCode 876(Middle of the Linked List, java) 0. 문제 https://leetcode.com/problems/middle-of-the-linked-list/ Middle of the Linked List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 연결 리스트(head)가 주어진다. - 전체 연결 리스트의 중간에 위치한 노드를 반환하는 것이 문제의 핵심이다. - 만약 중간에 위치한 노드가 2개라면 두 번째 중간 노드를 반환한다. 2. 문제 해설 a) 첫 번째 접근 - 이 .. 2022. 4. 26. 25. JPQL - 페이징 0. 개요 - JPQL에서 페이징을 사용하는 방법에 대해서 알아보자. 1. 개념 a) 페이징 이란 - 페이징이란 조회된 결과를 가져올 때, 몇 번째 데이터부터 몇 개를 가져올지 설정하는 것이다. - Oracle이나 MySQL을 사용하는 경우, 페이징을 설정하기 위한 쿼리가 굉장히 복잡하다. - 하지만, JPQL은 이를 2가지 메서드로 추상화하여 매우 편리하게 사용할 수 있다. 2. 페이징 API - JPA는 복잡한 페이징 쿼리를 다음 2가지 메서드(= API)로 추상화하여 제공한다. - 이 2가지 메서드는 설정한 방언에 따라 페이징 쿼리로 변환된다. a) setFirstResult(int startPosition) - setFirstResult() 메서드는 조회된 결과를 가져올 때의 시작 위치를 설정한다.. 2022. 4. 25. LeetCode 557(Reverse Words in a String III, java) 0. 문제 https://leetcode.com/problems/reverse-words-in-a-string-iii/ Reverse Words in a String III - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 문자열(s)이 주어진다. - 해당 문자열은 공백을 포함한 여러 개의 단어로 이루어져 있다. - 단어 단위로 역순으로 정렬하는 것이 문제의 핵심이다. 2. 문제 해설 - 어떤 문제를 푸는 방식은 다양하지만, 이 문제.. 2022. 4. 25. LeetCode 344(Reverse String, java) 0. 문제 https://leetcode.com/problems/reverse-string/ Reverse String - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 문자형 배열(char[] s)가 주어진다. - O(1)의 시간 복잡도를 가지는 추가 메모리만을 사용하여 s를 역순으로 정렬하는 것이 문제의 핵심이다. - 여기서 O(1)의 시간 복잡도를 가지는 추가 메모리가 의미하는 것은 기본 자료형을 사용하는 변수를 의미한다. - .. 2022. 4. 25. LeetCode 167(Two Sum II - Input Array Is Sorted, java 0. 문제 https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ Two Sum II - Input Array Is Sorted - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 오름차순으로 정렬된 정수형 배열(numbers)과 찾는 수(target)가 주어진다. - 배열을 탐색하여 두 요소의 합이 target을 이루는 짝을 찾고, 두 요소가 몇 번째 숫자인지 배열에 담아 반.. 2022. 4. 25. 이전 1 2 3 4 5 6 7 8 ··· 42 다음