我在vb.net中使用了sql代码
SELECT [Table1 Query].[amel_code], [Table1 Query].[kala_code], Sum([Table1 Query].
[SumOfqty]) AS SumOfSumOfqty FROM(
SELECT Table1.amel_code,
Table1.amani_code,
Table1.kala_code,
Sum(Table1.qty) AS SumOfqty
FROM Table1
GROUP BY Table1.amel_code,
Table1.amani_code,
Table1.kala_code HAVING (((Table1.amel_code)=[?]) AND ((Table1.amani_code)<[?]));
)
GROUP BY [Table1 Query].[amel_code], [Table1 Query].[kala_code];
这段代码工作正常,但是sql web。 Sheet提供以下错误:
关键字“SELECT”附近的语法不正确。 ')'附近的语法不正确。
请帮帮我。
答案 0 :(得分:2)
您需要在嵌套查询的末尾删除分号,并为其添加别名:
SELECT [Table1 Query].[amel_code], [Table1 Query].[kala_code], Sum([Table1 Query].[SumOfqty]) AS SumOfSumOfqty
FROM (
SELECT Table1.amel_code,
Table1.amani_code,
Table1.kala_code,
Sum(Table1.qty) AS SumOfqty
FROM Table1
GROUP BY Table1.amel_code,
Table1.amani_code,
Table1.kala_code
HAVING (((Table1.amel_code)=[?])
AND ((Table1.amani_code)<[?])) -- ; <<== Remove this semicolon
) [Table1 Query] -- <<== Add this alias
GROUP BY [Table1 Query].[amel_code], [Table1 Query].[kala_code];
答案 1 :(得分:0)
这就是你所缺少的:
1)为嵌套查询提供别名Table1 Query
。错误说明:无法确定[Table1 Query]
的用途。所以你必须将该别名赋予子查询。
SELECT [Table1 Query].[amel_code], [Table1 Query].[kala_code], Sum([Table1 Query].[SumOfqty]) AS SumOfSumOfqty
FROM(
SELECT Table1.amel_code,
Table1.amani_code,
Table1.kala_code,
Sum(Table1.qty) AS SumOfqty
FROM Table1
GROUP BY Table1.amel_code,
Table1.amani_code,
Table1.kala_code HAVING (((Table1.amel_code)=[?]) AND ((Table1.amani_code)<[?]))
) [Table1 Query]
GROUP BY [Table1 Query].[amel_code], [Table1 Query].[kala_code];
答案 2 :(得分:0)
每个子查询或嵌套查询都应该有别名。例如:
SELECT *
FROM (SELECT * FROM T1 WHERE ID>50) D
这是我对你的另一个问题的答案。