這是一個很簡單的問題,但筆者最SQL接觸不多。
做個學習紀錄。
問題:
SELECT STOCKID,MIN((LEAST(CAST(OPEN AS UNSIGNED))) AS max_value FROM yahoo_finance.table_price WHERE STOCKID IN ('4532','1615' ) and DATE BETWEEN '20240101' AND '20240507' GROUP BY STOCKID , 其中 AS max_value 輸出都是整數,有無方法可以變成是有小數點
使用 CAST 函數將每個欄位轉換為浮點數
類似CAST函數做進一步設定
CAST(OPEN AS DECIMAL(10,2))
SELECT STOCKID,MIN((LEAST(CAST(OPEN AS DECIMAL(10,2)))) AS max_value FROM yahoo_finance.table_price WHERE STOCKID IN ('4532','1615' ) and DATE BETWEEN '20240101' AND '20240507' GROUP BY STOCKID
這樣設定後,就可以透過語法直接輸出浮點數了。
沒有留言:
張貼留言