我有一个查询,计算电话接线员每天的查询次数
SELECT
[OperatorID],
DATEADD(day, DATEDIFF(day, 0, CreationDate), 0) AS CreationDate,
COUNT(*) AS EnquiryCount
FROM
[Enquiries] AS e
GROUP BY
[OperatorID], DATEADD(day, DATEDIFF(day, 0, CreationDate), 0)
但是,我想将Operator
表添加到此查询中,以便检索操作员名称
SELECT [OperatorID]
,[FirstName]
,[LastName]
FROM [Operators]
如果我在 group by 子句之前内部加入 2 个表:
SELECT [OperatorID]
, DATEADD(day, DATEDIFF(day, 0, CreationDate), 0) AS CreationDate
, COUNT(*) AS EnquiryCount
, st.FullName
FROM [Enquiries] AS e
INNER JOIN
(SELECT OperatorID, FirstName + ' ' + LastName AS FullName
FROM dbo.Operators
WHERE (Role = 'Operator')) AS o ON e.OperatorID = o.OperatorID
GROUP BY [OperatorID], DATEADD(day, DATEDIFF(day, 0, CreationDate), 0)
我收到以下错误:
列 'o.FullName' 在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。
我该如何解决这个问题?