Save the annual total of all income

-1

Hi guys I will be brief and precise with this question, I want to save in my mysql table ( total_anual ) that contains the following cells: year, anual; and guadar the annual total of my table ( factura ) contains the following cells: precio, día, mes, year, fecha

    
asked by Jhonse 15.09.2018 в 20:57
source

1 answer

0

Try the following:

INSERT INTO total_anual
SELECT year(fecha), sum(precio)
FROM factura
GROUP BY year(fecha);

For this, I used: 1. year (): Gets the year of a date field. 2. sum (): Summarizes a column. 3. GROUP BY: Groups the records by a specific field.

In addition to doing an "INSERT SELECT", if you would like to store only one specific year, add the following "FROM invoice":

WHERE year(fecha) = 2018
    
answered by 15.09.2018 в 23:09