분류 전체보기 423

[MySQL] SQL 내장함수 예시

1. addr의 시를 특별시로 변경하세요 (replace) # 서울시에서 '시'를 '특별시'로 바꾸기 select replace ('서울시','시','특별시'); # test3의 addr의 '시'를 '특별시'로 바꾸기 update test3 set addr = replace(addr,'시','특별시'); #select로 확인해보고 설정하기 = 설정이 바뀌지 않기 때문! select replace(addr,'시','특별시') from test3; 2. dep의 학과가 아닌 값들 뒤에 --학과로 만들기 (concat,right) 1) 학과가 있는 값을 찾아서 제외하고 붙이기 2) 학과가 없는 값을 찾아 붙이기 (뒤에 두 글자가 학과가 아닌경우, 학과를 concat) update test3 set dep = ..

[MySQL] product table - 이전 테이블의 값 중 하나만 가져와서 현재 테이블에 삽입

buy는 구매한 사람의 table buy table의 price를 product에서 찾아 넣기! //아래는 내가 한 방법 mysql> select*from buy; +-----+----------+----------------+-------+--------+---------------------+ | num | customer | product_name | price | amount | buy_date | +-----+----------+----------------+-------+--------+---------------------+ | 1 | 홍길동 | 폴라티셔츠 | 0 | 3 | 2023-03-24 17:22:02 | | 2 | 홍길순 | 에어나시 | 0 | 5 | 2023-03-24 17:22:..

[MySQL] ERD 생성

ERD : Entity Relationship Diagram 개체-관계 모델. 테이블간의 관계를 설명해주는 다이어그램 ( 개체- 관계 모델: 개체타입과 이들 간의 관계 타입을 현실세계를 개념적으로 표현 ) 기호 네모 □: 개체 타입 다이아몬드 ◇ : 관계 타입 동그라미 ○ : 속성 동그라미의 밑줄 : 기본키 속성 연결 선 : 개체와 속성을 연결 ERD 무료 생성 프로그램 https://www.erdcloud.com/ ERDCloud Draw ERD with your team members. All states are shared in real time. And it's FREE. Database modeling tool. www.erdcloud.com 예) 수강관리 프로그램 ERD 만들어보기 https:..

[MySQL] SQL 내장함수 : 논리함수 ( if , case ~ when ~then )

if 문 if문 : if(조건식, 참, 거짓); 다중 if문 : if(조건식, true, if(조건식, true, false)); 예시 ) at_repetition에 ( at_score =F 이거나 at_attend update attend set at_repetition = -> if(at_score = 'F' or at_attend where at_term = 1; 예시) at_score가 'A' 또는 'B'일 경우 'p'아니면 'f'를 넣으세요 mysql> update attend set at_pass = -> if(at_score = 'A' or at_score = 'B', 'p' , 'f' ); case ~ when ~then 문 case when 조건1 then 값1 when 조건2 then ..

[MySQL] ERD 수강관리 프로그램 4. join을 이용한 검색

1. A받은 학생의 명단(학번, 이름) mysql> select a.at_std_num, std_name, a.at_score from attend a -> join student s -> on at_std_num = s.std_num -> where at_score = 'A'; +------------+----------+----------+ | at_std_num | std_name | at_score | +------------+----------+----------+ | 2020160001 | 강철수 | A | | 2020123020 | 박철수 | A | +------------+----------+----------+ 2 rows in set (0.00 sec) 2. 재수강자 명단(학번, 이름,..

[MySQL] join 사용

: 여러개의 테이블을 묶어 하나의 테이블로 만들어 사용하는 것 ⭐ 원하는 데이터가 다른 테이블에 흩어져 있을 경우 join을 사용 예) A를 받은 학생의 명단 (학번, 이름) attend의 at_score와 student의 std_name, std_num이 필요 join의 종류 : 내부 조인(inner join) / 외부 조인(outer join) / 상호 조인(cross join) inner join (그냥써도 inner로 간주) select 열 목록 from 기준 테이블명(관계 테이블=가운데 있는 테이블) (inner) join 참조테이블명 on 조인조건(fk) where 조건 group by having order by desc / asc ; 기준 테이블 = 보통 묶어주는 중심 테이블 inner은 ..

[MySQL] ERD 수강관리프로그램 3.업데이트 (update, if, case)

1. attend 테이블의 수강년도(at_year) 을 2023으로 변경 mysql> update attend set at_year = 2023; Query OK, 16 rows affected (0.00 sec) Rows matched: 16 Changed: 16 Warnings: 0 mysql> select * from attend; +--------+------------+-------------+---------+---------+--------+----------+-----------+-------+---------------+----------+ | at_num | at_std_num | at_co_code | at_year | at_term | at_mid | at_final | at_att..

[MySQL] ERD 수강관리프로그램 2. 내부 데이터 삽입

1. student 테이블 데이터 삽입 insert into student values (), (), () ; mysql> insert into student values -> ('2019160123','정봉준','컴퓨터공학과',2,64), -> ('2019456001','강길동','디자인',3,60), -> ('2020123001','강나래','화학공학',1,21), -> ('2020123020','박철수','화학공학',1,20), -> ('2020160001','강철수','컴퓨터공학',1,20), -> ('2020160002','나영희','컴퓨터공학',1,19); Query OK, 6 rows affected (0.01 sec) Rec..

[MySQL] ERD 수강관리 프로그램 1. 생성 (속성)

✔ table생성 mysql> create database school; Query OK, 1 row affected (0.01 sec) mysql> use school; Database changed mysql> create table student( -> std_num varchar(10), -> std_name varchar(20) not null, -> std_major varchar(20), -> std_term int, -> std_point int, -> primary key(std_num)); Query OK, 0 rows affected (0.01 sec) mysql> desc student; +-----------+-------------+------+-----+---------+---..

[MySQL] SQL 내장함수 : 문자열 함수

SQL 문자열 함수 Concat(문자1, 문자2..) : 문자열 연결 2023 03 27 같은 날짜 연결시에 사용 mysql> select concat("ad",'cd'); +-------------------+ | concat("ad",'cd') | +-------------------+ | adcd | +-------------------+ 1 row in set (0.00 sec) length(문자) : 문자의 길이 영어의 경우 length사용 한글의 경우 lengrh사용시 *2로 출력 -> char_length로 사용 mysql> select length('가나다'); +------------------+ | length('가나다') | +------------------+ | 6 | +-----..