buy는 구매한 사람의 table
buy table의 price를 product에서 찾아 넣기!
//아래는 내가 한 방법
mysql> select*from buy;
+-----+----------+----------------+-------+--------+---------------------+
| num | customer | product_name | price | amount | buy_date |
+-----+----------+----------------+-------+--------+---------------------+
| 1 | 홍길동 | 폴라티셔츠 | 0 | 3 | 2023-03-24 17:22:02 |
| 2 | 홍길순 | 에어나시 | 0 | 5 | 2023-03-24 17:22:02 |
| 3 | 이순신 | 양털 겨울 코트 | 0 | 1 | 2023-03-24 17:22:02 |
+-----+----------+----------------+-------+--------+---------------------+
3 rows in set (0.00 sec)
mysql> update buy set price=
-> (select price from product where name="폴라티셔츠")
-> where product_name = '폴라티셔츠';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> update buy set price=
-> (select price from product where name="에어나시")
-> where product_name = '에어나시';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update buy set price=
-> (select price from product where name="양털 겨울 코트")
-> where product_name = '양털 겨울 코트';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from buy;
+-----+----------+----------------+-------+--------+---------------------+
| num | customer | product_name | price | amount | buy_date |
+-----+----------+----------------+-------+--------+---------------------+
| 1 | 홍길동 | 폴라티셔츠 | 15000 | 3 | 2023-03-24 17:22:02 |
| 2 | 홍길순 | 에어나시 | 9000 | 5 | 2023-03-24 17:22:02 |
| 3 | 이순신 | 양털 겨울 코트 | 50000 | 1 | 2023-03-24 17:22:02 |
+-----+----------+----------------+-------+--------+---------------------+
3 rows in set (0.00 sec)
// create 부터 찾아 넣는 방법 (선생님)
https://jungeun980906.tistory.com/86
'DB > 명령프롬프트 - mysql' 카테고리의 다른 글
[MySQL] SQL 내장함수 : 정보함수 (0) | 2023.03.28 |
---|---|
[MySQL] SQL 내장함수 예시 (0) | 2023.03.28 |
[MySQL] ERD 생성 (0) | 2023.03.28 |
[MySQL] SQL 내장함수 : 논리함수 ( if , case ~ when ~then ) (0) | 2023.03.28 |
[MySQL] ERD 수강관리 프로그램 4. join을 이용한 검색 (0) | 2023.03.28 |