我使用gorm查询mysql sum sql,但是,发生错误:
sql: Scan error on column index 0, name "transaction_amount": converting driver.Value type []uint8 ("-1,225.67") to a float64: invalid syntax
这是我定义的结构:
type AdsPayment struct {
Model
SellerID string `gorm:"size:32"`
TransactionType string `json:"transactionType"`
Currency string `gorm:"size:8" json:"currency"`
BaseAmount float64 `gorm:"type:decimal(10,2)" json:"baseAmount"`
TransactionAmount float64 `gorm:"type:decimal(10,2)" json:"transactionAmount"`
TaxAmount float64 `gorm:"type:decimal(10,2)" json:"taxAmount"`
InvoiceID string `gorm:"size:64" json:"invoiceId"`
PostedDate time.Time `json:"postedDate"`}
这是查询代码:
var ads AdsPayment
DB.Select(floatFmt+"(SUM(transaction_amount), 2) As transaction_amount").Group(dateFmt).First(&ads, "seller_id=? And currency=? And "+dateFmt+"=?", "A3VFS4SD0I640V", "USD", "2019-01")