I am trying to handle nested queries using gorm and I am having troudble figuring this out.
The queries:
SELECT smId AS 'slimeId', slStatus, slPPIV, slHighRiskSituation,
(SELECT count(rnIg) FROM ruins WHERE rnSquidStatus = 'Holding on'
AND rnSmId = smId) AS 'holdingOn',
(SELECT count(rnIg) FROM ruins WHERE rnSquidStatus = 'In system' AND rnSmId = smId)
AS 'inSystem', smSuspectedCorona,
IF(smStatusClosed != 0, 1, 0) as statusClosed, smSurge,
(SELECT GROUP_CONCAT(rnName) FROM ruins WHERE rnSquidStatus = 'Holding on' AND rnSmId = smId)
as 'ruinsOnHold',
(SELECT GROUP_CONCAT(rnName) FROM ruins WHERE rnSquidStatus = 'In system' AND rnSmId = smId)
as 'ruinsInSystem' FROM slimes WHERE slId != 0 GROUP BY slId HAVING slId > 0
So I can get some of it done which is pretty basics, the problem is when nesting comes which I don't know what to do in that case
var data []SlimeResponse
db := service.gormdb
db = db.Select("smId as slimeId", "slStatus", "slPPIV", "slHighRiskSituation")
db = db.Where("smId != ?", 0).Group("smId ").Having("smId > ?", 0)
db = db.Table("slimes").Find(&data)
Tried using Where method but didn't work same as Joins but couldn't get it to work