我有这样一个查询:
I have a query like this:
SELECT col1, col2, col3, col4, col5, SUM(col6) AS total FROM table_name WHERE col1 < 99999 GROUP BY 1,2,3,4,5GROUP BY 语句在这里实际完成了吗?如果没有逗号分隔的整数,查询就无法正常工作。
What does the GROUP BY statement actually accomplish here? The query does not work properly without the comma-separated integers.
推荐答案这相当于写作:
SELECT col1, col2, col3, col4, col5, SUM(col6) AS total FROM table_name WHERE col1 < 99999 GROUP BY col1, col2, col3, col4, col5/列在列表中的顺序位置表示,从1开始。
The numbers are the values/columns in the select-list expressed by ordinal position in the list, starting with 1.
这些数字用于强制;那么添加了在选择列表中使用表达式的功能。表达式可能会变得笨拙,并且并非所有DBMS都允许您使用GROUP BY子句中的选择列表中的显示标签或列别名,所以偶尔使用列号是有帮助的。
The numbers used to mandatory; then the ability to use the expressions in the select-list was added. The expressions can get unwieldy, and not all DBMS allow you to use 'display labels' or 'column aliases' from the select-list in the GROUP BY clause, so occasionally using the column numbers is helpful.
在您的示例中,最好使用名称 - 它们很简单。而且,一般来说,只要可以,就使用名称而不是数字。
In your example, it would be better to use the names - they are simple. And, in general, use names rather than numbers whenever you can.
更多推荐
GROUP BY语句中以逗号分隔的整数是什么完成的?
发布评论