如何解决以下问题?
Msg 512,Level 16,State 1,Line 1 Subquery返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。声明已经终止。
我尝试将频率设为:
| Frequency
| 19
| 23
但不知何故,通过触发此查询,我无法获得超过我的价值:
SELECT ts.TimeDifference/ ts.EntryAmount as Frequency
FROM
(
SELECT COUNT(*) as EntryAmount,
(
SELECT DATEDIFF(d, t.minimum, t.maximum)
FROM (SELECT max(Date) AS maximum, min(Date) AS minimum FROM Times GROUP BY column1, column2, column3, column4 HAVING COUNT(*) > 1) t
) AS TimeDifference
FROM Times
) ts
谢谢。
答案 0 :(得分:1)
您最内层的子选择返回多个结果。您将获得第1,2,3和4列的最小和最大PER组合。摆脱子选择,它将解决问题。
{{1}}
答案 1 :(得分:0)
您可以使用聚合函数:
SELECT ts.TimeDifference/ ts.EntryAmount as Frequency
FROM
(
SELECT COUNT(*) as EntryAmount,
(
SELECT Max(DATEDIFF(d, t.minimum, t.maximum))
FROM (SELECT max(Date) AS maximum, min(Date) AS minimum FROM Times GROUP BY column1, column2, column3, column4 HAVING COUNT(*) > 1) t
) AS TimeDifference
FROM Times
) ts