DB 63

[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 | +-----..