Search code examples
mysqlvirtualrowsum

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

Solution

  • 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.