quiz



풀이

# 데이터베이스 생성
create database malldb_test;

# 데이터베이스 지정
use malldb_test;

# 테이블 생성
create table goodsinfo(
num int,
code char(5) primary key,
name char(30),
price int,
maker char(20)
);

# 테이블 속성 확인
desc goodsinfo;

# 테이블 데이터 삽입
insert into goodsinfo (num, code, name, price, maker)
values
(1, 'A001', '디지털TV', 520000, '제일'),
(2, 'A002', 'DVD', 240000, '제일'),
(3, 'U101', 'DSLR', 830000, '우수'),
(4, 'U102', '전자사전', 160000, '우수'),
(5, 'H704', '전자렌지', 90000, '하나');

#테이블 자료 조회
select * from goodsinfo;

# 4. 번호 컬럼의 3 자료에서 가격을 750000으로 수정합니다. 
update goodsinfo set price = 750000 where num = 3;

# 5. 제조사가 [제일] 모든 자료를 조회합니다. 
select * from goodsinfo where maker like '제일';

# 6. 상품명에서 [TV]라는 단어가 포함된 자료를 모두 조회합니다. 
select * from goodsinfo where name like '%TV%';

# 7. 상품코드의 내림차순으로 정렬합니다. 
select * from goodsinfo order by code desc;

# 8. 제조사의 오름차순으로 1 정렬하고 가격의 오름차순으로 2 정렬합니다. 
select * from goodsinfo order by maker asc, price asc;

#9. 상품코드 [A002] 자료를 삭제합니다.
delete from goodsinfo where code = 'A002';

select * from goodsinfo;

Leave a comment