第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我想按距離對數(shù)據(jù)進(jìn)行排序,但失敗了

我想按距離對數(shù)據(jù)進(jìn)行排序,但失敗了

Go
梵蒂岡之花 2022-08-09 16:56:13
我想按距離對數(shù)據(jù)進(jìn)行排序,但失敗了。表位type Place struct {    gorm.Model    CountyName    string     Name          string      Address       string     ServiceTime   string     Phone         string      BusinessScope string      Remark        string     Lng           float64    Lat           float64     Type          uint }這有效:func PlaceList(placeType, fieldName, fieldValue string, pageNum, pageSize int) (places []Place, err error) {    result := DB.Scopes(Paginate(pageNum, pageSize)).Scopes(Filter(placeType, fieldName, fieldValue)).Find(&places)    return places, result.Error}我試圖對它進(jìn)行排序,但這不起作用:func PlaceList(currentLng, currentLat, placeType, fieldName, fieldValue string, pageNum, pageSize int) (places []Place, err error) {    var distance = "places.lng, places.lat, power((%s - places.lng),2) + power((%s - places.lat),2) as distance"    var selectDistance  = fmt.Sprintf(distance, currentLng, currentLat)    result := DB.Table("places").Select(selectDistance).Scopes(Paginate(pageNum, pageSize)).Scopes(Filter(placeType, fieldName, fieldValue)).Order("distance").Find(&places)    return places, result.Error}
查看完整描述

1 回答

?
有只小跳蛙

TA貢獻(xiàn)1824條經(jīng)驗 獲得超8個贊

現(xiàn)在沒事了


func PlaceList(currentLng, currentLat, placeType, fieldName, fieldValue string, pageNum, pageSize int) (places []Place, err error) {

    var distance = "*, power((%s - places.lng),2) + power((%s - places.lat),2) as distance"

    var selectDistance = fmt.Sprintf(distance, currentLng, currentLat)

    result := DB.Debug().Table("places").Select(selectDistance).Scopes(Paginate(pageNum, pageSize)).Scopes(Filter(placeType, fieldName, fieldValue)).Order("distance").Find(&places)

    return places, result.Error

}


查看完整回答
反對 回復(fù) 2022-08-09
  • 1 回答
  • 0 關(guān)注
  • 97 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號