[英]Mysql sum as last row
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
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.在 SQL 中,您不能有一列仅出现在一行中,同样,您也不能有一列不包含其他行中的所有列。因此,不可能有一行包含独特的东西。 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.
但是,您可以将计算的列添加到数据集中的所有行中,或者在返回数据后在调用代码中进行计算。
I think what you are looking for is GROUP BY WITH ROLLUP
you will find details on that in the MySQL manual.我认为您正在寻找的是
GROUP BY WITH ROLLUP
您可以在 MySQL 手册中找到详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.