Generating an SQL query for verbose and subtotals (MySQL)

I have a common SQL task, but I cannot find a clear path to a solution. I have a table downloadswith columns, download_date, image_file_id, credits. What I want at the end is the part, plus the subtotal creditsfor the day at the end of each day. For instance.

2010-10-06 123456 5
2010-10-06 234567 20
                  25
2010-10-07 234678 15
etc.

I can use SUM()it GROUP BYto get daily subtotals, but I’d like a convenient way to get a result set containing both in the correct order, so I don’t need to scan the data again in client code to organize the subtotals with lowercase strings.

+3
source share
1

, MySQL ROLLUP:

SELECT download_date, image_file_id, credits 
    GROUP BY download_date, image_file_id WITH ROLLUP

- . . MySQL.

+6

Source: https://habr.com/ru/post/1769036/


All Articles