SQL to add a summary row to MySQL result set

前端 未结 4 1461
感动是毒
感动是毒 2021-01-24 21:18

If I have a MySQL table such as:

I want to use SQL to calculate the sum of the PositiveResult column and also the NegativeResult colu

4条回答
  •  终归单人心
    2021-01-24 21:25

    This should be handled at least one layer above the SQL query layer.

    The initial query can fetch the detail info and then the application layer can calculate the aggregation (summary row). Or, a second db call to fetch the summary directly can be used (although this would be efficient only for cases where the calculation of the summary is very resource-intensive and a second db call is really necessary - most of the time the app layer can do it more efficiently).

    The ordering/layout of the results (i.e. the detail rows followed by the "footer" summary row) should be handled at the presentation layer.

提交回复
热议问题