例如,我有
SELECT SUBSTRING([Path], 0, 5) AS [Directory]
, COUNT([Directory])
FROM [MyDatabase]
GROUP BY [Directory];
但我收到“无效的列名”错误。
例如,我有
SELECT SUBSTRING([Path], 0, 5) AS [Directory]
, COUNT([Directory])
FROM [MyDatabase]
GROUP BY [Directory];
但我收到“无效的列名”错误。
这应该有效:
SELECT SUBSTRING([Path], 0, 5) AS [Directory]
, COUNT(1)
FROM [MyDatabase]
GROUP BY SUBSTRING([Path], 0, 5);
问题是 count() 中使用的列名中的别名,我也不明白为什么在计算时需要两列。尝试
SELECT COUNT(SUBSTRING([Path], 0, 5))
FROM [MyDatabase];
如果你需要两列,那么在这里:
SELECT SUBSTRING([Path], 0, 5) AS [Directory]
, COUNT(SUBSTRING([Path], 0, 5) )
FROM [MyDatabase]
GROUP BY SUBSTRING([Path], 0, 5);