我正在通过mysql内部连接尝试以下组。它说的是未知的列名。你可以帮我解决这个问题。我在内部联接中的“SELECT Min(Id)FROM testinbcalls group by lc.DBID”中收到“查看组中的未知列名DBID”的错误。如果groupby是,我可以修改此查询吗?不允许。我试过“”SELECT Min(Id)FROM testinbcalls WHERE Id = lc.DBID“而不是group by但它没有用。我不希望将检查移动到where子句,因为我希望在内连接本身上过滤记录。任何人都可以帮助我。谢谢
SELECT DISTINCT ic.Id as `Id`, lc.DBID,
init.Name as Init,
lc.TargetNumber as PhoneNumber,
CONCAT(us.FirstName,' ',us.Surname) as UserName,
iout.Name as Outc FROM
testcalls ic
INNER JOIN testinit init on ic.InitId=init.Id
INNER JOIN users us on ic.UserId=us.Id
INNER JOIN testinbcalls lc ON ic.Id=lc.CallId AND lc.DBID IS NOT NULL AND ic.Id=(**SELECT Min(Id) FROM testinbcalls group by lc.DBID** )
INNER JOIN (SELECT MIN(Id) Id FROM testinbcalls group by lc.DBID) mincallid ON ic.Id=mincallid.Id
INNER JOIN icomes iout on ic.OutId=iout.Id
WHERE ic.AssignedDateTime between '2015-06-08 00:00:00' and '2015-06-09 23:59:59' ORDER BY Id DESC limit 250;
答案 0 :(得分:0)
您将其更改为删除表别名lc
。有了它,你实际上是在引用外部查询表。
INNER JOIN (SELECT MIN(Id) AS MinId FROM testinbcalls group by DBID)