How to display the following when view query effect
Some examples checked online, found the MYSQL does not support the grouping.
CodePudding user response:
First, you need to add a classification to the original table (TYPE), the same classification data, statistics to a total,Then write a separate query to return all of the total,
Finally combined with the query statement UNION ALL the original table,
SELECT * FROM (
SELECT a T1. *, 1 Y FROM TABLE_NAME T1
UNION ALL
The SELECT T2. *, 2 Y FROM TABLE_NAME T2 GOURP BY T2. TYPE the
T ORDER) BY T.T YPE, T.Y Lin;
The final ORDER BY is to ensure that the same classification (TYPE) of the data together, Y is in ORDER to guarantee the basic data in the former, statistics,
CodePudding user response:
Light With the query is not meet you so perfect, if use Group By With Rollup is also short of effect you want,If you want to write like you, need to write a function that returns a table,
Then function and writes the data exchange rate one table,
CodePudding user response:
Accumulation in vernier cycle minimum date date less than or equal to the maximum, inserted into a temporary tableCodePudding user response:
Idea is to have two query, statistics monthly, and yearly, small gauge for one of the biggest month the number of days, such as the 2019-03-31, so he must be at the end of each month; A total number to one of the biggest month, such as 2019-13-01; And then the detailed, subtotal, total union all together, in the positive sequence is arranged by date, eg:Select * from (
Select * from t1
UNION ALL
Select CONCAT (DATE_FORMAT (date, 'yyyy - MM),' - 32) date, 'subtotal' goods, 'sale,' remain, the sum (profit) profit from t1 GROUP BY DATE_FORMAT (date, 'yyyy - MM)
UNION ALL
Select CONCAT (DATE_FORMAT (date, 'yyyy'), '13-01) the date of goods' total', 'sale,' remain, the sum (profit) profit from t1
) the order by the date
CodePudding user response: