I hove some data
ID |Price | Date
01 | 100 | 2019-04-11
02 |200 | 2019-04-12
03 |300 | 2019-05-10
How can I get the SUM of Price from April's MONTH (4) only?
this will work:
from Table1 a
group by month(a.Date);
you can also make functional based index on month(a.Date) for faster processing as GordonLinoff mentioned!!!
I strongly recommend writing the logic like this, assuming that you mean April of 2019 rather than all Aprils over time:
where t.date >= '2019-04-01' and
t.date < '2019-05-01';
When you use a function like month() on a column, that almost always prevents the use of indexes on the column. Direct comparisons are fine, though.