DB
-
index - mysqlDB 2023. 8. 13. 17:18
INDEX란? RDBMS에서 인덱스(INDEX)는 데이터베이스의 특정 테이블의 한 또는 여러 열에 대한 자료 구조로, 레코드(ROW)를 빠르게 찾는데 도움을 준다. 인덱스는 대형 데이터베이스에서 데이터 검색 속도를 크게 향상시킬 수 있다. INDEX를 생성하는 방법 1. 이미 테이블이 존재한다면? - 데이터의 중복을 허용하는 컬럼의 인덱스를 거는 경우. CREATE INDEX [index의 별칭] ON [table명] ([column명]) 예> create index member_name_idx name on member (name); - 데이터의 중복을 허용하지 않은 컬럼(들)의 인덱스를 거는 경우. CREATE UNIQUE INDEX [index의 별칭] ON [table 명] ([column명], ..
-
MySQL - SELECT(4주차)DB 2023. 6. 2. 15:46
◎수업내용 Subquery with 절 SQL 문법 - 문자열 SQL 문법 - CASE Subquery 1. 특정값을 활용하기 2. 특정 범위를 활용하기 3. 새로운 테이블 처럼 활용하기 ◎ 특정값 활용하기 SELECT avg(likes) FROM checkins WHERE user_id = '4b8a10e6'; 이 값을 활용해서 sql 문을 활용해보자. SELECT checkin_id , user_id , likes, (SELECT avg(likes) FROM checkins WHERE user_id = '4b8a10e6') AS avg_likes_user FROM checkins; 지금처럼 특정값을 하나의 컬럼으로 활용해서 사용할 수도 있다. 다음은 WHERE 절에서의 특정값 활용을 해보자 SELEC..
-
MySQL - SELECT(3주차)DB 2023. 6. 2. 14:49
수업내용 join 문 union join 문 SELECT [테이블 컬럼 ( 필드 ) ], [테이블 컬럼 ( 필드 ) ], ... FROM [TABLE1 명] JOIN(INNER JOIN, LEFT JOIN, OUTTER JOIN ..) [TABLE2 명] ON 절(join 조건절) WHERE 절 GROUP BY 절 ... ORDER BY [테이블 컬럼 (필드)] (DESC, ASC), ... join문은 내가 조회하고자하는 내용이 2개의 테이블에 존재할 때, 사용한다. 먼저 on 절에 두개의 테이블이 어떠한 관계로 연결을 지어주어 테이블을 합칠 것인지를 정해준다. sql의 실행순서를 한번 정리해보자 sql 실행순서 from + join (어떤 테이블에서) ▶ on + where(어떤 조건을 가지고 ) ▶..
-
MySQL - SELECT(2주차)DB 2023. 6. 2. 14:35
수업내용 group by order by group by SELECT [테이블 컬럼 ( 필드 ) ], [테이블 컬럼 ( 필드 ) ], ... FROM [TABLE 명] GROUP BY [테이블 컬럼 (필드)], ... group by 를 해주면, 해당 테이블은 지정된 필드로 묶이게 된다. 그 이후에, 집계함수를 사용하게 되면, 묶인 그룹별로 집계함수가 동작을 한다. SELECT name 성씨 FROM users ; >> 결과 : name 필드만을 보여준다. SELECT name 성씨, count(name) AS `갯수` FROM users ; >> 결과 : 그룹없이 단순히 테이블 내의 모든 이름의 count를 진행 이** 은 이전의 결과에 맨 위에 있던게 단순히 나온 것. SELECT name 성씨, c..
-
MySQL - SELECT(1주차)DB 2023. 6. 1. 23:10
SELECT 문 SELECT [테이블 컬럼 ( 필드 ) ], [테이블 컬럼 ( 필드 ) ], ... FROM [TABLE 명] 내가 검색하고자하는 테이블을 조회할 때 사용이 된다. where Select 쿼리문으로 가져올 데이터에 조건을 걸어주는 것을 의미 where 절 연습 전제조건 orders TABLE에는 유저의 아이디(user_id), 결제일?(created_at), 결제 수단(payment_method) 등의 정보가 있음 "payment_method 가 'kakaopay' 다"라는 조건을 토대로 검색 SELECT * -- 보여줄 필드. * : 모든 필드 선택 조건 FROM orders -- 테이블명 WHERE payment_method = 'kakaopay'; where 절에 오는 형태는 다양하..