❗ERD 설계 Tool에서 export
https://radiant515.tistory.com/208
❗배민 ERD로 SQL문 실습
✏️프로젝트 생성 후 테이블 만들기
✏️더미데이터 생성하기
✏️쿼리문 실습
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
|
/*배민 쿼리문 실습*/
# 전체 테이블 조회
show tables;
#1. 회원의 개인 정보 조회
select userName, loginId, email, phone, userGrade from users;
#2. 사업자의 개인 정보 조회
select ownerId, ownerName, address, registrationNumber from owners;
#3. 가게의 정보 조회
select storeName, rating, introdution, address, operatingHours, dayoff, area from stores;
#4. 한 가게의 메뉴 조회
select stores.storename as storeName,
menus.menuName as menuName,
menus.price as price
from menus
join stores on Stores.storeId = 1 and Stores.storeId = Menus.storeId;
#5. 특정 지역 가게 조회
select stores.storeName as storeName,
stores.address as address,
stores.operatingHours as operatingHours,
stores.dayoff as dayoff,
stores.phone as phone
from stores where area = '안양시';
#6. 한 사업자가 운영하는 가게 목록
select owners.ownerName as ownerName,
owners.registrationNumber as registrationNumber,
storeName as storeName
from Stores
join owners on Stores.ownerId = 2 and Stores.ownerId = Owners.ownerId;
#7. 한 회원이 작성한 리뷰 목록
select users.userName as userName,
menus.menuName as menuName,
reviews.rating as rating,
reviews.content as content
from reviews, users
join menus where users.userId = 1 and users.userId = Reviews.userId and Reviews.menuId = Menus.menuId;
#8. 한 회원이 갖고 있는 쿠폰 목록
select users.userName as userName,
coupon.couponName as couponName,
coupon.deductedPrice as deductedPrice,
coupon.expirationDate as expirationDate,
coupon.minOrderAmount as minOrderAmount
from coupon
join users on Users.userId = 2 and coupon.userId = Users.userId;
#9. 한 회원이 주문한 메뉴
select users.userName as userName,
stores.storeName as storeName,
menus.menuName as menuName,
menus.price as price
from ordermenu
join users, stores, menus
where users.userID = OrderMenu.userId and users.userID=3 and Stores.storeId = OrderMenu.storeId
and ordermenu.menuId = menus.menuId;
#10. 한 회원이 갖고 있는 찜 목록
select users.userName as userName,
stores.storeName as storeName
from likes
join users, stores
where Likes.userId = Users.userId and Likes.storeId = Stores.storeId and Users.userId = 2;
|
cs |
728x90
반응형
'🔻Extracurricular Activity > UMC' 카테고리의 다른 글
[UMC 3기] server 6주차-2 (0) | 2022.11.02 |
---|---|
[UMC 3기] server 6주차-1 (0) | 2022.11.02 |
[UMC 3기] server 5주차-1 (0) | 2022.10.21 |
[UMC 3기] server 4주차-3 (0) | 2022.10.12 |
[UMC 3기] server 4주차-2 (0) | 2022.10.12 |