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

[MySQL] student table - 22=1학년, 23=2학년, 24=3학년, 25=4학년으로 하는 grade속성 추가

mysql> update student set grade = 1 where age = 22; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 ysql> update student set grade = 3 where age = 24; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> update student set grade = 2 where age = 23; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> update st..

[MySQL] student table - 테이블의 값을 다른 테이블로 옮기기 (4학년 친구들을 졸업)

- 새로운 테이블을 생성해서! 1. student_4를 student 테이블과 같은 구조로 생성 Create table new_table(복사본) like table(원본); 원본 테이블의 구조를 복사하여 복사 테이블을 생성 create table student_4 like student; 2. Grade가 4인 학생만 student_4로 이동 insert into문 활용해서 한번에 값 이동 values(조건) = select * from student where grade=4; insert into student_4(num, name, age, address, major, score, grade) -> select * from student where grade = 4; 3..

[MySQL] product table - 테이블 생성 예제

mysql> create database shop; //데이터베이스 생성 Query OK, 1 row affected (0.01 sec) mysql> show databases; //데이터베이스 생성 확인 +--------------------+ | Database | +--------------------+ | ezen | | information_schema | | mysql | | performance_schema | | sakila | | shop | | sys | | test | | world | +--------------------+ 9 rows in set (0.00 sec) mysql> use shop; //shop데이터베이스 사용 Database changed mysql> create ..

[MySQL] product table - product테이블을 이용한 예제

1. type_a별로 상품의 개수와 price 합계 출력 mysql> select type_a, sum(price) as '합계', count(num) as '개수' -> from product -> group by type_a -> order by type_a; +------------+--------+------+ | type_a | 합계 | 개수 | +------------+--------+------+ | 아우터 | 280400 | 2 | | 티셔츠 | 55800 | 4 | | 패션운동복 | 80000 | 2 | +------------+--------+------+ 3 rows in set (0.00 sec) 2. price가 16000..