[SQL] 為何應該要使用 “IS NULL" 而不是 “= NULL"?

當我們想要找出某些欄位是 NULL 的資料…

做為資料工作者,在處理資料的時候經常會遇到所謂的空值「NULL」,也常看到這樣的值被存在資料庫的欄位中,當我們使用 SQL 想要找出某些欄位中是空值的資料,就會使用像下方這樣的 WHERE 去做篩選,但這樣其實無法得到我們想要的結果。

SELECT 
    column_1,
    column_2
FROM `my_table`
WHERE column_1 = NULL
閱讀更多»

快速了解 VS Code 最新更新!聊聊 v1.58 的新功能

這次 VS Code 更新到 v1.58 版本啦!利用這篇文章來分享幾個本人覺得還滿值得一提的新功能吧!

比較有感的更新

繁體中文介面!

雖然英文介面已經用很習慣,但繁體中文用起來也還滿新鮮的!

繁中介面的歡迎頁

Terminals in the editor

現在可以將 terminal 建立或是移動到程式碼編輯的那個區塊,這個彈性還滿方便的,之後就不用被限制 terminal 只能放在下方了!

移動和新增的方式有四種,個人覺得第 2 點的直接拖曳 tab 感覺最方便

閱讀更多»

2017.9.3 Dictionaries

Dictionaries

1.

# 在 dictionary 中創造新的 key

dict_name[new_key] = new_value

2.

# 改變其中一個 key 的 value

dict_name[key] = new_value

3.

# 刪除一個 key

del dict_name[key_name]

 


stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}

del stock['banana']
print(stock)

{‘apple’: 0, ‘orange’: 32, ‘pear’: 15}

閱讀更多»

2017.9.2 List / Slices

List

# 使用 for loop 定義 number 為 my_list 中的各項數據
# 使 my_list 不被變更,可重複使用

my_list = [1,9,3,8,5,7]
  for number in my_list:
    print(2 * number)

2
18
6
16
10
14


# 也可另外創一個 empty list
# 視情況去增加 .append() 或 排列 .sort()

start_list = [5, 3, 1, 2, 4]
square_list = []
  for number in start_list:
    square_list.append(number ** 2)
    square_list.sort()

print (square_list)

[1, 4, 9, 16, 25]

閱讀更多»

2017.9.1 Codecademy-旅費計算

計算旅費的練習


def hotel_cost(nights):   # 每晚旅館費用140元
  return 140 * nights

def plane_ride_cost(city):    # 不同城市的機票錢
  if city == "Charlotte":
    return 183
  elif city == "Tampa":
    return 220
  elif city == "Pittsburgh":
    return 222
  elif city == "Los Angeles":
    return 475

def rental_car_cost(days):    # 每天租車費用與折扣
  total = 40 * days
  if days >= 7:
    total -= 50
  elif days >= 3:
    total -= 20
return total

# 利用所有已經設定之方程式,計算旅費總額
# spending_money為額外支出

def trip_cost(city,days,spending_money):
  return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money

# 飛洛杉磯5天,額外支出600元

print(trip_cost("Los Angeles",5,600))    

本次旅費總共 = 1955元


自我練習: 計算之前去日本旅遊的大概費用

def hotel(nights):    # 住宿每天約845元台幣
  return 845 * nights

def plane_ticket_go(city_go):    # 去程機票
  if city_go == "Tokyo":
    return 3978

def plane_ticket_back(city_back):    # 回程機票(包含不同機場價格)
  if city_back == "Tokyo":
    return 5779
  elif city_back == "Osaka":
    return 12660 * 0.272               # 當時匯率約 0.272

def trip_cost(city_go,city_back,nights,spending_money):   # 旅費總額計算(額外支出設定日幣->台幣)
  spending_money = spending_money * 0.272
  return hotel(nights) + plane_ticket_go(city_go) + plane_ticket_back(city_back) + spending_money

# 東京進出,8晚,額外支出設定10萬

print('案例1-總花費:')
print(trip_cost("Tokyo","Tokyo",8,100000))

# 東京進,大阪出,33晚,額外支出設定30萬

print('案例2-總花費:')
print(trip_cost("Tokyo","Osaka",33,300000))

案例1-總花費:
43717.0
案例2-總花費:
116906.52