I want to mix 2 sql queries, one to get total amount in a particular year, and other to know the amount in a particular month of a particular year
SELECT SUM(money) As Anual FROM Deposito WHERE Year(FechaDeposito)=2011
SELECT SUM(money) As monthly FROM Deposito WHERE Year(FechaDeposito)= 2011 AND Month(FechaDeposito)=10
How to do that in the most efficent way ?
Simply combining your two queries would give
It will perform terribly however. Ideally you want an index on
FechaDeposito, and to construct date ranges to test against instead of running functions over the column, e.g.