---
# System prepended metadata

title: 8/23回家作業

---

# 8/23回家作業
## 請依照下列情境，將對應的交易明細與餘額資料寫入HCMIO與TCNUD資料表，並繳交SQL Insert語句：
- 2022/08/19，以單價33.45元買進1張味王（1203）股票，委託單號CB001
```sql = 
INSERT INTO `test`.`hcmio` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `BsType`, `Price`, `Qty`, `Amt`, `Fee`, `Tax`, `NetAmt`, `ModDate`, `ModTime`, `ModUser`) VALUES ('20220819', 'F62W', '04', 'CB001', '1203', 'B', '33.45', '1000', '33450', '48', '0', '-33498', '20220823', '150921', 'Jake');
```
```sql = 
INSERT INTO `test`.`tcnud` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `Price`) VALUES ('20220819', 'F62W', '04', 'CB001', '1203', '33.45');
```
- 2022/08/19，以單價57.6元買進3張聯華（1229）股票，委託單號CB002
```sql = 
INSERT INTO `test`.`hcmio` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `BsType`, `Price`, `Qty`, `Amt`, `Fee`, `Tax`, `NetAmt`, `ModDate`, `ModTime`, `ModUser`) VALUES ('20220819', 'F62W', '04', 'CB002', '1229', 'B', '57.6', '3000', '172800', '246', '0', '-173046', '20220823', '150921', 'Jake');
```
```sql = 
INSERT INTO `test`.`tcnud` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `Price`, `Qty`, `RemainQty`, `Fee`, `Cost`) VALUES ('20220819', 'F62W', '04', 'CB002', '1229', '57.6', '3000', '3000', '246', '173046');
```
- 2022/08/19，以單價9.83元買進7張愛之味（1217）股票，委託單號CB003
```sql = 
INSERT INTO `test`.`hcmio` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `BsType`, `Price`, `Qty`, `Amt`, `Fee`, `Tax`, `NetAmt`, `ModDate`, `ModTime`, `ModUser`) VALUES ('20220819', 'F62W', '04', 'CB003', '1217', 'B', '9.83', '7000', '68810', '98', '0', '-68908', '20220823', '150921', 'Jake');
```
```sql = 
INSERT INTO `test`.`tcnud` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `Price`, `Qty`) VALUES ('20220819', 'F62W', '04', 'CB003', '1217', '9.83', '7000');
```
- 2022/08/19，以單價352元買進10張瑞昱（2379）股票，委託單號CB004
```sql = 
INSERT INTO `test`.`hcmio` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `BsType`, `Price`, `Qty`, `Amt`, `Fee`, `Tax`, `NetAmt`, `ModDate`, `ModTime`, `ModUser`) VALUES ('20220819', 'F62W', '04', 'CB004', '2379', 'B', '352', '10000', '3520000', '5016', '0', '-3525016', '20220823', '150921', 'Jake');
```
```sql = 
INSERT INTO `test`.`tcnud` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `Price`, `Qty`, `RemainQty`, `Fee`, `Cost`) VALUES ('20220819', 'F62W', '04', 'CB004', '2379', '352', '10000', '10000', '5016', '3525016');
```
- 2022/08/19，以單價90.7元買進5張陽明（2609）股票，委託單號CB005
```sql = 
INSERT INTO `test`.`hcmio` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `BsType`, `Price`, `Qty`, `Amt`, `Fee`, `Tax`, `NetAmt`, `ModDate`, `ModTime`, `ModUser`) VALUES ('20220819', 'F62W', '04', 'CB005', '2609', 'B', '90.7', '5000', '453500', '646', '0', '-454146', '20220823', '150921', 'Jake');
```
```sql = 
INSERT INTO `test`.`tcnud` (`TradeDate`, `BranchNo`, `CustSeq`, `DocSeq`, `Stock`, `Price`, `Qty`, `RemainQty`, `Fee`, `Cost`) VALUES ('20220819', 'F62W', '04', 'CB005', '2609', '90.7', '5000', '5000', '646', '454146');
```
## 請依下列賣出價格，計算前部分作業寫入的餘額的未實現損益:
未實現損益:股票現值-賣出手續費-賣出交易稅-買入成本-買入手續費
- 味王：未實現損益=35000-50-105-33450-48=1347元
- 聯華：未實現損益=170100-242-510-172800-246=-3698元
- 愛之味：未實現損益=70770-101-212-68810-98=1549元
- 瑞昱：未實現損益=3550000-5059-10650-352000-5016=9275元
- 陽明：未實現損益=445500-635-1337-453500-646=-10618元


