Select
tblActivity.RoomID,
tblRoomEquipment.EquipmentType,
COUNT(tblActivity.Name) AS NumberOfActivities
from tblActivity
inner join tblRoomEquipment
on tblRoomEquipment.RoomID= tblActivity.RoomID
where tblRoomEquipment.EquipmentType = 'W'
group by tblActivity.RoomID
在这里,我想显示具有特定设备类型的RoomID在这种情况下是'W'的次数,所以我使用了来自tbl Activity的Name列来确定W出现的次数名称ID将显示其相当混乱的解释。
因此本身就是问题所在:列出在其中包含白板的房间中发生的活动的数量。 (5)
错误:
Msg 8120,Level 16,State 1,Line 1 Column 'tblRoomEquipment.EquipmentType'在选择列表中无效,因为 它不包含在聚合函数或GROUP BY中 子句。
答案 0 :(得分:2)
SELECT
a.RoomID,
re.EquipmentType,
COUNT(a.Name) AS NumberOfActivities
FROM tblActivity as a
INNER JOIN tblRoomEquipment as re ON re.RoomID= a.RoomID
WHERE re.EquipmentType = 'W'
GROUP BY a.RoomID, re.EquipmentType