-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_basic3
More file actions
92 lines (56 loc) · 2.09 KB
/
sql_basic3
File metadata and controls
92 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
수행 연습
create database library;
use library;
create table products(
pid int primary key,
pname varchar(50) not null,
price int not null default 100,
indate datetime not null,
starff varchar(20) null
);
create table orders(
oid int primary key auto_increment,
oname varchar(30) not null,
otel varchar(20) not null,
pid int not null,
odate datetime not null,
foreign key(pid) references products(pid)
);
create table book(
bid int primary key auto_increment,
bname varchar(40) not null,
bman varchar(20) null,
pname varchar(20) not null,
price int not null
);
insert into book(bid,bname,bman,pname,price)
values (1,'삼국지','김민수','대림출판',5500),
(2,'동물농장','남궁영호','초원당',6000),
(3,'백중','박춘삼','콩미디어',4500),
(4,'변신',null,'대림출판',6000),
(5,'대항해시대','초훈','콩미디어',12000);
select * from book;
select pname from book;
select distinct pname from book;
select bid,bname,price * 0.9 from book;
select bid,bname from book where bman = '남궁영호';
select bid,bname from book where pname = '대림출판' and price >= 6000;
select bname,pname from book where price between 5000 and 8000;
select bid,bname,bman from book where bman like '%수';
select bid,bname,bman,pname from book where pname like '___';
select bname,bman,pname from book where bman is null;
select bname,bman,pname from book where bman is not null;
select * from book order by bname; -- 내림차순 desc
select * from book order by price desc ,bname asc;
select count(*) from book;
select count(bman) from book where bname is not null;
select count(distinct pname) from book;
select avg(price),max(price),min(price) from book;
select pname,count(*) from book group by pname;
select pname,avg(price) from book group by pname;
select pname,count(*) from book group by pname having count(pname) >= 2;
select pname,count(*) from book group by pname limit 1;
update book set bman = '조영수' where bid = 2;
delete from book where bid = 2;
delete from book;
select * from book;