我的数据库上有这 3 个表。我正在尝试将bId
哪个 FK 分组到Baptism
. BSponsors
是洗礼赞助商的表格,因此bId
如果我不打算对它进行分组,显然该列将在我的页面上重复显示。所以我尝试了下面的代码,但弹出错误说:
列在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句 SQL Server 中
SELECT p.pId, p.Lname, p.Fname, p.Mname, p.BirthDate, p.HomeAddress,
p.PlaceOfBirth, p.Age, p.BirthDate, b.*, s.*,
(SELECT sp.Fname+' '+sp.Lname FROM Profile sp WHERE sp.pId=b.pId) AS child,
(SELECT sp.Fname+' '+sp.Lname FROM Profile sp WHERE sp.pId=b.fatherID) AS father,
(SELECT sp.Fname+' '+sp.Lname FROM Profile sp WHERE sp.pId=b.motherID) AS mother,
(SELECT sp.Fname+' '+sp.Lname FROM Profile sp WHERE sp.pId=b.guardianID) AS guardian,
(SELECT sp.Fname+' '+sp.Lname FROM Profile sp WHERE sp.pId=b.revID) AS rev,
(SELECT sp.Fname+' '+sp.Lname FROM Profile sp WHERE sp.pId=s.pId) AS sponsors
FROM Baptism b
INNER JOIN Profile p
ON p.pId=b.pId
INNER JOIN BSponsors s
ON b.bId = s.bId
GROUP BY s.bId