我的进度数据库的示例,opdetail表
invoice invline article size qty ---------------------------------------- 905155 1 Shoe 10 5 905155 2 Slipper 3 2 905155 2 Slipper 4 6 905155 2 Slipper 5 1 905156 1 Boot 10 1 905156 1 Boot 11 1 905157 1 Slipper 5 4 905157 2 Shoe 8 6
一个简单的SQL select语句,从OpenEdge编辑器运行,只返回我需要的,一个发票列表及其总数量: -
SELECT invoice, sum(qty) FROM opdetail GROUP BY qty ORDER BY invoice ASC
905155 14 905156 2 905157 10
但是: - 当通过DSN从ASP页面运行时,我必须列出GROUP BY中的两个字段,否则进度返回GROUP BY错误
SELECT invoice, sum(qty) FROM opdetail GROUP BY qty, invoice ORDER BY invoice ASC
905155 5 905155 9 905156 2 905157 4 905157 6
它没有总结数量,并且似乎考虑了行号,即使行号在我的sql语句中不起作用。任何人都可以对此有所了解,或者我如何考虑行号来做总数量的总和?谢谢!
答案 0 :(得分:3)
您在聚合函数中使用qty
,然后在group by
上使用这没有任何意义,您应该在其他列上group by
作为
SELECT
invoice,
sum(qty) FROM opdetail
GROUP BY invoice ORDER BY invoice ASC