Board index » delphi » SQL Question: How to group data by month

SQL Question: How to group data by month

Hello,

    I have a bank account table that has 2 important fields: date and
amount
    I have to write a query to group (and sum) this data by month.
    I also have no idea on how to achieve this using SQL!
    Can anyone help me on this SQL statement?

    TIA!
    Tulius Lima

 

Re:SQL Question: How to group data by month


Quote
>    I have a bank account table that has 2 important fields: date and
>amount
>    I have to write a query to group (and sum) this data by month.
>    I also have no idea on how to achieve this using SQL!
>    Can anyone help me on this SQL statement?

I assume you are using Paradox or dbase table so that this is a question on
Local SQL.  The answer is you can not do it in a single query.  You can do it in
two queries.
The first query you need an answer set that includes the year.  You can do that
with the Extract function

Select  Extract(Year from D."Date") as YR , D.Amount
from Account D

Next you can use DbiMakePerminate method to create a table from a query

dbiMakePerminate(query1.handle,'temp.db',true)
This will create a table in your PrivateDir.  Use an alias or explicit path if
you want it some other place.

You should be able to figure out what to do next

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads