汇总函数和其他列 [英] Aggregate function and other columns

查看:68
本文介绍了汇总函数和其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL查询是否可以返回一些普通列和一些聚合列?

Is it possible for a SQL query to return some normal columns and some aggregate ones?

like:

Col_A | Col_B | SUM
------+-------+------
   5  |   6   |  7


推荐答案

您应使用按语句分组


GROUP BY语句与
函数和
函数一起用于将结果集按
一或多个列进行分组。

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

例如:

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name

您可以看到一个完整的示例此处

You can see a complete example here.

这篇关于汇总函数和其他列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆