SQL 超新手問題

我想問下...如果我create一個table 入邊有個attributes 係記錄金錢...我要俾埋個"$"佢
應該點寫個satement?
thx@@

未試過...多數係set o個個field做money..
之後o係call佢時自己加個$落去...

TOP

加多個$ attributes
咁你第時想轉都易d~

TOP

如果個field type 係string的話........
MSSQL: update table set amount = '$' + amount
MySQL: update table set amount = concat('$',amount)
PostgreSQL: update table set amount = '$' || amount

TOP

'$' is just a representation.  You need to keep the money amount as number because you will be performing many arithmetic operation in this column.

TOP

原帖由 jzu 於 2008-12-14 20:24 發表
如果個field type 係string的話........
MSSQL: update table set amount = '$' + amount
MySQL: update table set amount = concat('$',amount)
PostgreSQL: update table set amount = '$' || amount

if amount is a numeric field, you will die

TOP

原帖由 alphaau 於 2008-12-15 15:02 發表

if amount is a numeric field, you will die


i know, that's why i have assumed if the field type is string

TOP

呢d涉及數字的唔應該用string
因為一但要做運算就會比較麻煩
你另願係頂頭寫明係用"$"做單位會更好吧

TOP

原帖由 sunhikari 於 2008-12-15 16:06 發表
呢d涉及數字的唔應該用string
因為一但要做運算就會比較麻煩
你另願係頂頭寫明係用"$"做單位會更好吧

或許出display 先響加formatting

TOP

format o既野輸出/顯示 時先至做.
database 儲數值.

如果用 MySQL, 可以:

SELECT CONCAT('$',FORMAT(field1, 2)) FROM table1

FORMAT( a, b ) 係將 a 顯示成 #,###.## 格式, b 係小數後位數.

呢d function 唔同 SQL Server 做法唔同.



[ 本帖最後由 laputafish 於 2008-12-16 10:53 編輯 ]

TOP