GROUP BY语句中以逗号分隔的整数是什么完成的?

编程入门 行业动态 更新时间:2024-10-28 18:26:29
本文介绍了GROUP BY语句中以逗号分隔的整数是什么完成的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样一个查询:

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,5

GROUP 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语句中以逗号分隔的整数是什么完成的?

本文发布于:2023-10-18 02:59:47,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:逗号   整数   中以   语句   GROUP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!