# 0324_AMASTek森淨科技
## 1.ugly_number
```
def nthUglyNumber(n):
ugly_nums = [1]
index_2, index_3, index_5 = 0, 0, 0
while len(ugly_nums) < n:
next_ugly = min(ugly_nums[index_2] * 2, ugly_nums[index_3] * 3, ugly_nums[index_5] * 5)
ugly_nums.append(next_ugly)
if next_ugly == ugly_nums[index_2] * 2:
index_2 += 1
if next_ugly == ugly_nums[index_3] * 3:
index_3 += 1
if next_ugly == ugly_nums[index_5] * 5:
index_5 += 1
# print('index_2, index_3, index_5 -',index_2, index_3, index_5)
# print('ugly_nums ',ugly_nums)
return ugly_nums[-1]
n = 10
result = nthUglyNumber(n)
print(result)
```
---
## 2_ERDiagram
dbdiagram 線上圖
https://dbdiagram.io/d/641c18d3296d97641d8a2db6

```
// 基本 - 人員
// User 帳戶資訊:帳戶名稱、帳號、密碼、 詳細資訊(1對1)、安全群組權限(多對多)、隸屬模組(基本資料管理)、建立時間
Table users {
id int [pk, increment]
username VARCHAR(50) [not null]
account VARCHAR(50) [not null]
password VARCHAR(100) [not null]
person_id int [ref: - personnel.id]
group_id int [ref: <> security_group.id]
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// User 詳細資訊:姓名、電話、建立時間
Table personnel {
id int [pk, increment]
name VARCHAR(50)
phone VARCHAR(20)
created_at TIMESTAMP
}
// 基本 - 產品 : 產品名稱、價格、敘述、隸屬模組(基本資料管理)、建立時間
Table products{
id int [pk, increment]
name VARCHAR(50)
price DECIMAL(10,2)
description VARCHAR(200)
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// 基本 - 權限:群組名稱、模組權限(多對多)、隸屬模組(基本資料管理)
Table security_group{
id int [pk, increment]
name VARCHAR
security_group_model_ids INT [ref: <> models.id]
model_id INT [ref: > models.id]
}
// 基本 - 模組:模組名稱
Table models{
id int [pk, increment]
name VARCHAR(50)
}
// 生產追蹤管理 - 訂單管理
// 員工、訂購人、訂單總額、日期、隸屬模組(生產追蹤管理)、建立時間
Table orders{
id int [pk, increment]
employee_id INT [ref: - users.id]
ordering_person VARCHAR(20)
order_total DECIMAL(10,2)
date_order TIMESTAMP
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// 生產追蹤管理 - 訂單管理 - 商品清單
// 源訂單號(多對一)、產品編號(一對一)、數量、價格、建立時間
Table order_line{
id int [pk, increment]
order_id INT [ref: > orders.id]
product_id INT [ref: - products.id]
quantity INT
price_total DECIMAL(10,2)
created_at TIMESTAMP
}
// 生產追蹤管理 - 生產報工
// 員工編號、簽到、簽退、隸屬模組(生產追蹤管理)、建立時間
Table production_record{
id int [pk, increment]
employee_id INT [ref: - users.id]
check_in TIMESTAMP
check_out TIMESTAMP
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// 庫存管理 - 入庫
// 產品編號、數量、員工、入庫時間、隸屬模組(庫存管理)、建立時間
Table inbound{
id int [pk, increment]
product_id INT [ref: - products.id]
quantity INT
employee_id INT [ref: - users.id]
inbound_time TIMESTAMP
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// 庫存管理 - 出庫
// 產品編號、數量、員工、出庫時間、隸屬模組(庫存管理)、建立時間
Table outbound{
id int [pk, increment]
product_id INT [ref: - products.id]
product_uom_qty INT
employee_id INT [ref: - users.id]
outbound_time TIMESTAMP
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// 報表匯出 - 庫存報表
// 隸屬模組(報表匯出)、建立時間
Table inventory_report{
id int [pk, increment]
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// 源報表編號(多對一)、產品編號、數量
Table inventory_report_items{
id int [pk, increment]
report_id INT [ref: > inventory_report.id]
product_id INT [ref: - products.id]
product_uom_qty INT
}
// 報表匯出 - 生產記錄報表
// 隸屬模組(報表匯出)、建立時間
Table production_report{
id int [pk, increment]
model_id INT [ref: > models.id]
created_at TIMESTAMP
}
// 源報表編號(多對一)、產品編號、數量
Table production_report_items{
id int [pk, increment]
report_id INT [ref: > production_report.id]
product_id INT [ref: - products.id]
product_uom_qty INT
}
```
---
## 3.second_highest_salary
```
SELECT
max(salary)
FROM
Employee
WHERE
salary < ( SELECT max(salary) FROM Employee )
```