DB/명령프롬프트 - mysql 예시 24

[MySQL] ERD 대학수강프로그램 2. 정보넣기

insert into student values (2020123001,'김영철',2,0), (2020123002,'나영희',2,0), (2020160001,'강철수',2,0), (2020160002,'박철수',2,0), (2020456001,'강군',2,0); insert into subject (su_code,su_title,su_point,su_time) values ('msc001','대학수학',3,3), ('com001','컴퓨터개론',2,2), ('com002','운영체제',3,3), ('abc001','글쓰기',2,2), ('abc002','영어',2,3); insert into professor values (2005789001,'홍길동',60,'B동 302호','재직','정교수'), (20..

[MySQL] ERD 대학수강프로그램 1. 생성

mysql> CREATE TABLE student ( -> st_num int NOT NULL, -> st_name varchar(20) NOT NULL, -> st_term int NOT NULL DEFAULT 0, -> st_point int NOT NULL DEFAULT 0 -> ); Query OK, 0 rows affected (0.01 sec) mysql> CREATE TABLE professor ( -> pr_num int NULL, -> pr_name varchar(20) NOT NULL, -> pr_age int NOT NULL, -> pr_room varchar(45) NOT NULL, -> pr_state varchar(45) NOT NULL DEFAULT '재직', -> pr_pos..

[MySQL] ERD 수강관리 프로그램 - 5. join 예제

1. 과목별 중간, 기말, 출석, 과제 합계 mysql> select co_name as '과목', sum(at_mid+at_final+at_attend+at_hw) as '점수 합계' -> from attend -> join course on at_co_code = co_code -> group by co_name -> ; +----------------+-----------+ | 과목 | 점수 합계 | +----------------+-----------+ | 컴퓨터개론 | 135 | | 대학수학기초 | 173 | | 기초전기 | 125 | | 프로그래밍일반 | 142 | +----------------+-----------+ 4 rows in set (0.00 sec) mysql> select co..

[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 수강관리 프로그램 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] 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; +-----------+-------------+------+-----+---------+---..