GORM是否支援使用SQL的IIF函數?
P粉547362845
P粉547362845 2023-09-01 16:06:17
0
1
299
<p>我有一個用於作業的表,一個用於解決方案的表,還有一個用於學生的表。 我想檢索所有的作業,並且對於每個作業,我想添加一個“標誌”,顯示當前登入的學生是否嘗試過該作業。 </p> <p>我嘗試了這個:</p> <pre class="brush:golang;toolbar:false;">import ( "fmt" "gorm.io/gorm" "encoding/json" "github.com/my_organisation/myorg-repo/db" ) var database *gorm.DB var solutions []db.Solution var listOfAsnmtIDs []uint func myfuncn (w http.ResponseWriter, r *http.Request){ //... _ = database.Table("solutions").Where("pupil_id = ?", pupil.ID).Select("assignment_id").Find(&solutions) for _, solution := range solutions { listOfAsnmtIDs = append(listOfAsnmtIDs, solution.AssignmentID) } response := database.Table("assignments").Select(`id, created_at, IIF((id IN ?), 'attempted', 'Not attempted') as attempted`, listOfAsnmtIDs).FindmtID;allAssignments) if response.RowsAffected < 1 { respondToClient(w, 404, nil, "No assignments found") return } //... } </pre></p>
P粉547362845
P粉547362845

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!