Data Analysis

Data Analysis/TIL

[LeetCode] Exchange Seats_CASE WHEN THEN 서브쿼리

문제 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..

Data Analysis/TIL

[LeetCode] Product Price at a Given Date

문제 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' 이후인 제품들만 ..

Data Analysis/SQL

[MySQL] REGEXP 정규표현식 정리

정규표현식에서 사용되는 기호를 Meta문자라고 표현한다. 표현식 의미 ^x 문자열의 시작 표현. x문자로 시작됨 x$ 문자열의 종료 표현. x문자로 종료됨 .x 임의의 한 문자의 자리수를 표현. 문자열이 x로 끝남 x+ 반복 표현. x문자가 한 번 이상 반복됨 x? 존재 여부 표현. x문자가 존재할 수도, 존재하지 않을 수도 있음을 의미 x* 반복 여부 표현. x 문자가 0번 또는 그 이상 반복됨을 의미 x|y or 표현. x 또는 y문자가 존재함 (x) 그룹 표현. x를 그룹으로 처리함 (x)(y) 그룹들의 집합을 표현. 앞에서부터 순서대로 번호를 부여하여 관리하고, x, y는 각 그룹의 데이터로 관리 (x)(?:y) 그룹들의 집합에 대한 예외 표현. 그룹 집합을으로 관리되지 않음을 의미 x{n} 반복..

Data Analysis/Pandas

[Udemy] DataFrame_basic

Nan = Not a number = 결측치 Nan df.decribe() - count, 50%(median) df.describe() count : 결측치가 아닌 값들의 개수 age_50% : 모든 승객의 50%가 28세 미만, 나머지 50%가 28세 이상 데이터 자료형이 객체(object)인 열 선택하고 싶을 때 df.describe(include ='O') : 모든 열에 대해 데이터 자료형이 객체(object)인 열을 선택할 수 있음 매개변수 정보 불러오기 Shift + Tab : 메소드에 대한 모든 매개변수 정보를 볼 수 있다. Shift + Tab*2 : 매개변수에 대한 더 자세한 정보 Shift + Tab*3 : 매개변수에 대한 더 자세한 정보 + 입력하는 동안 n초 켜져 있음 Shift +..

Data Analysis/TIL

[LeetCode] Delete Duplicate Emails_DELETE

문제 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 후, 이메일이 같은 것들 중 아이디가 큰 것을 지우도록 조건을 작성해준다.

Data Analysis/TIL

[LeetCode] Count Salary Categories_필요한 범주 테이블 만들기

문제 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..

Data Analysis/TIL

[Programmers] 가격대 별 상품 개수 구하기_FLOOR

문제 PRODUCT 테이블에서 만원 단위의 가격대 별로 상품 개수를 출력하는 SQL 문을 작성해주세요. 이때 컬럼명은 각각 컬럼명은 PRICE_GROUP, PRODUCTS로 지정해주시고 가격대 정보는 각 구간의 최소금액(10,000원 이상 ~ 20,000 미만인 구간인 경우 10,000)으로 표시해주세요. 결과는 가격대를 기준으로 오름차순 정렬해주세요. 풀이 시도한 풀이(성공) SELECT CASE WHEN price = 10000 AND price = 20000 AND price = 30000 AND price < 40000 THEN 30000 ..

Data Analysis/TIL

[LeetCode] Students and Examinations_CROSS JOIN

문제 Write a solution to find the number of times each student attended each exam. Return the result table ordered by student_id and subject_name. The result format is in the following example. Input: Students table: +------------+--------------+ | student_id | student_name | +------------+--------------+ | 1 | Alice | | 2 | Bob | | 13 | John | | 6 | Alex | +------------+--------------+ Subjects t..

Data Analysis/TIL

[LeetCode] Product Sales Analysis III_조건에 맞는 타칼럼 추출하기

문제 Write a solution to select the product id, year, quantity, and price for the first year of every product sold. Return the resulting table in any order. Input: Sales table: +---------+------------+------+----------+-------+ | sale_id | product_id | year | quantity | price | +---------+------------+------+----------+-------+ | 1 | 100 | 2008 | 10 | 5000 | | 2 | 100 | 2009 | 12 | 5000 | | 7 | 20..

Data Analysis/SQL

[MySQL] JOIN에 따른 ON/WHERE 제약 조건 구분하기

(INNER)JOIN에 따른 ON/WHERE 절 제약 조건 ON절은 WHERE절보다 순서 상 실행 속도가 더 빠르다. FROM → ON → JOIN → WHERE INNER JOIN을 사용하는 경우, ON이든 WHERE든 어디에 조건을 주든 상관이 없다. 즉, 아래의 세 쿼리는 서은ㅇ에 약간의 차이는 있을 수 있지만 결과물에 차이를 보이지는 않는다. -- 첫 번째 쿼리 SELECT D.deptno, D.dname, E.ename, E.sal FROM dept D, emp E WHERE D.deptno = E.deptno AND E.sal > 2000; -- 두 번째 쿼리 SELECT D.deptno, D.dname, E.ename, E.sal FROM dept D INNER JOIN emp E ON D...

J pathfinder
'Data Analysis' 카테고리의 글 목록