我有这个SQL查询
SELECT LEFT(ORIGINALPATH, 34), count(originalpath) as docType1,
(SELECT count(originalpath)
FROM docType2
WHERE ORIGINALPATH LIKE 'D:\era-server\16\ibosdata\00001\%'
GROUP BY LEFT(ORIGINALPATH, 34)) AS [dcoType2]
FROM docType1
WHERE ORIGINALPATH LIKE 'D:\era-server\16\ibosdata\00001\%'
GROUP BY LEFT(ORIGINALPATH, 34)
ORDER BY LEFT(ORIGINALPATH, 34);
但是我遇到了以下错误
子查询返回了多个值。当 子查询遵循=,!=,<,<=,>,> =,或当子查询用作 表达式。
尽管我没有使用这样的运算符。请帮忙。
答案 0 :(得分:1)
您可以删除内部分组依据并尝试吗?分组依据可能是在子查询中创建多个行。编辑:添加条件,以确保分组依据与同一分组元素相同。
SELECT LEFT(ORIGINALPATH, 34), count(originalpath) as docType1,
(SELECT count(originalpath)
FROM docType2 de
WHERE ORIGINALPATH LIKE 'D:\era-server\16\ibosdata\00001\%'
and LEFT(de.ORIGINALPATH, 34) = LEFT(d1.ORIGINALPATH, 34)
GROUP BY LEFT(ORIGINALPATH, 34)) AS [dcoType2]
FROM docType1 d1
WHERE ORIGINALPATH LIKE 'D:\era-server\16\ibosdata\00001\%'
GROUP BY LEFT(ORIGINALPATH, 34)
ORDER BY LEFT(ORIGINALPATH, 34);