C# OLEDBEException对SQL查询C中的两个字段求和
我正在c中使用OLEDB连接 我的问题是:C# OLEDBEException对SQL查询C中的两个字段求和,c#,oledbconnection,C#,Oledbconnection,我正在c中使用OLEDB连接 我的问题是: "SELECT [City],[Column1]+[Column2] FROM [Issuer$] WHERE ([Column1] > 1) GROUP BY [City]" 我总是收到错误 ERROR : You tried to execute a query that does not include the specified expression 'Column1+Column2' as part of an aggre
"SELECT [City],[Column1]+[Column2]
FROM [Issuer$] WHERE ([Column1] > 1)
GROUP BY [City]"
我总是收到错误
ERROR : You tried to execute a query that does not include the specified
expression 'Column1+Column2' as part of an aggregate function.
我的问题是:我做错了什么
我试图寻找像这样添加字段的人,但没有找到有相同问题的人
谢谢,因为您使用的是分组,选择中的列需要是组成该组的记录的集合。所以你需要使用
SELECT City,
SUM(Column1 + Column2)
FROM Issuer
WHERE (Column1 > 1)
GROUP BY City
…将返回组条目中每一行的所有Column1+Column2值相加。我假设SUMColumn1-Column2会起作用,因为您的问题有代码将列值相加。因此,我的答案也是如此。显然,您可以将其更改为减法或其他对您的应用程序有意义的内容。