Question: Good day to all, i've to do a query that sums some columns together.

```
$sqlannoprima = "SELECT fascia_prezzo,data,giorno,
   SUM (a1,a2,a3,a4,a5,a6,a7,a8) as atot, 
   SUM (g1,g2,g3,g4,g5,g6,gtesi,gg) as gtot,
   SUM (f1,f2,f,3,f4) as ftot, 
   SUM (lt1,lt2,lt3,lt4,ltg) as lttot,
   FROM giorni 
   WHERE STR_TO_DATE(giorno, '%d/%m/%Y')- INTERVAL 1 YEAR BETWEEN 
   STR_TO_DATE('" . $d1 . "', '%d/%m/%Y')- INTERVAL 1 YEAR 
   AND STR_TO_DATE('" . $d2 . "', '%d/%m/%Y')- INTERVAL 1 YEAR 
   GROUP BY giorno 
   ORDER BY STR_TO_DATE(giorno, '%d/%m/%Y')- INTERVAL 1 YEAR";

```

but SQL returns an error when i try to print the results.

> 
> Notice: Trying to get property of non-object in
>  E:\EasyPHP\data\localweb\cdm\stats.php on line 377
> 
> 
> 

And this is at line 377: 

```
$risultatoannoprima = $queryannoprima->num_rows;

```

What am i missing?
Thanks a lot

Answer: 
You need to remove the last `,` after `lttot` in your sql
Also,you had better use `(INTERVAL 1 YEAR)` instead of `INTERVAL 1 YEAR` directly

```
  $sqlannoprima = "SELECT fascia_prezzo,data,giorno,
   SUM (a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8) as atot, 
   SUM (g1 + g2 + g3 + g4 + g5 + g6 + gtesi + gg) as gtot,
   SUM (f1 + f2 +f3 + f4) as ftot, 
   SUM (lt1 + lt2 + lt3 + lt4 + ltg) as lttot
   FROM giorni 
   WHERE STR_TO_DATE(giorno, '%d/%m/%Y')- (INTERVAL 1 YEAR) BETWEEN STR_TO_DATE('" . $d1 . "', '%d/%m/%Y')- (INTERVAL 1 YEAR) AND STR_TO_DATE('" . $d2 . "', '%d/%m/%Y')- (INTERVAL 1 YEAR) GROUP BY giorno 
   ORDER BY (STR_TO_DATE(giorno, '%d/%m/%Y')- (INTERVAL 1 YEAR))";

```
```
SELECT fascia_prezzo,data,giorno,SUM(a1) as a1,SUM(a2) as a2,SUM(a3) as a3,SUM(a4) as a4,SUM(a4) as a4,SUM(a5) as a5,SUM(a6) as a6,SUM(a7) as a7,SUM(a8) as a8,(SUM(a1) + SUM(a2) + SUM(a3) + SUM(a4) + SUM(a5) + SUM(a6) + SUM(a7) + SUM(a8)) as atot FROM giorni
WHERE STR_TO_DATE(giorno, '%d/%m/%Y') BETWEEN STR_TO_DATE('" . $d1 . "', '%d/%m/%Y') AND STR_TO_DATE('" . $d2 . "', '%d/%m/%Y')
GROUP BY fascia_prezzo,data,giorno
ORDER BY STR_TO_DATE(giorno, '%d/%m/%Y')

```