subQuery:=model.DB().Table("cp_achievement a").Joins("JOIN cp_relation r ON a.cp_id = r.id").Select("type,MAX(score) AS max_score").Group("type")
subQuery:=model.DB().Table("cp_achievement a").Joins("JOIN cp_relation r ON a.cp_id = r.id").Select("type,MAX(score) AS max_score").Group("type")
iferr:=model.DB().Model(CpAchievement{}).Where("(type, score) IN (?)",subQuery).Find(&achievements).Error;err!=nil{
iferr:=model.DB().Model(CpAchievement{}).Joins("INNER JOIN cp_relation r ON cp_id = r.id").Where("(type, score) IN (?)",subQuery).Find(&achievements).Error;err!=nil{