Mysql sum 作为最后一行
是否可以将所有数字字段的总和放在一组行的最后?
到目前为止,我正在使用一个非常简单的查询,例如:
SELECT
*,
SUM((UNIX_TIMESTAMP(end) - UNIX_TIMESTAMP(start))/3600)
FROM
times
Is it possible to have the SUM of all numaric fields in the last of a set of rows?
As of now, I'm using a very simple query such as:
SELECT
*,
SUM((UNIX_TIMESTAMP(end) - UNIX_TIMESTAMP(start))/3600)
FROM
times
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 SQL 中,你不能有一个列只出现在一行中,同样,你也不能有一行不包含其他行中的所有列。因此,不可能有一行包含唯一的内容。但是,您可以将计算列添加到数据集中的所有行,或者在返回数据后在调用代码中进行计算。
in SQL you cant have a column that appears in only one row, likewise, you also cant have a row that doenst contain all the columns from the other rows.. So having a row that contains something unique is not possible. You can, however, add the calculated column to all rows in the dataset or do the calculation in the calling code after the data is returned.
我认为您正在寻找的是
GROUP BY WITH ROLLUP
您可以在 MySQL 手册中找到有关该内容的详细信息。I think what you are looking for is
GROUP BY WITH ROLLUP
you will find details on that in the MySQL manual.