LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   MySQL SUM Query (https://www.linuxquestions.org/questions/programming-9/mysql-sum-query-51881/)

zimba 03-26-2003 03:32 PM

MySQL SUM Query
 
Hia, first hello to everybody I'm new to the forum :-)

I'm totally lost with a complicated sql query, can smbdy help me ?

Look :
I got a table with reparations incommings:

Fields : RepID, RepDateTime, RepTotalCost

Now I'd like to SUM() all incomming reparations for each day in the table.
Is it possible to do it in one query ?

Hope :-P

zimba

j-ray 03-27-2003 08:37 AM

select SUM(RepTotalCost) from db where RepDateTime<somevalue and RepDateTime>othervalue;

u may use BETWEEN function in the where clause too

if u want to select sums of a lot of days at once i guess u need to make a temporary table for each day or switch to a db that supports subselects

zimba 03-27-2003 03:10 PM

Thanks a lot j-ray,

I just read today that MySQL 4.1 supports subselects so I don't have to change my DB, just upgrade :-P

cf. MySQL Press Release 21 Jan 2003

thanx,
zimba

j-ray 03-28-2003 09:55 AM

nice to hear that. it's a great improvement that was announced for long. gonna get me that too. ;-)
cheers, jens


All times are GMT -5. The time now is 07:27 PM.