DB 63

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

[MySQL] 원하는 위치의 데이터 추출 limit

원하는 위치의 데이터 추출 : limit 시작번지, 개수; 시작번지부터 개수만큼 추출 보통 서식의 맨뒤에 위치! mysql> select * from student limit 0,3; +------+--------+------+---------+----------+-------+ | num | name | age | address | major | score | +------+--------+------+---------+----------+-------+ | 1111 | 홍길동 | 23 | seoul | computer | 89 | | 2222 | 강길순 | 24 | seoul | English | 87 | | 3333 | 이순신 | 22 | Inchen | English ..

[MySQL] Database 확인 show, use, select

mysql> show databases; / /mysql의 데이터베이스를 보여주세요 mysql> use test; // Database의 test를 사용합니다 mysql> show tables; // test의 테이블을 보여주세요 mysql> select*from test1; // test1 table 전체출력 mysql> select*from test1 where address = "서울시"; // address가 서울시인 test1 table전체 출력 Microsoft Windows [Version 10.0.19045.2728] (c) Microsoft Corporation. All rights reserved. C:\Users\EZEN-217T>mysql -uroot -pezen //mysql에 연..