Jump to content

Simple total query not working


Twitch
Go to solution Solved by Twitch,

Recommended Posts

Hello Fellow Freaks,
 
I have written two simple queries to grab some totals.
 
This query successfully gets the subtotal of each row based on the rate and the amount of minutes
 

select slip_rate AS RATE_PER_HOUR,ROUND( (
SUM( TIMESTAMPDIFF( 
MINUTE , slip.slip_start, slip.slip_end ) ) )
) AS MINS,ROUND( (
SUM( TIMESTAMPDIFF( 
MINUTE , slip.slip_start, slip.slip_end ) ) /60 ) * slip_rate, 2
) AS SUB_TOTAL
FROM slip WHERE project_id=3 GROUP BY slip_id

The above code returns:

RATE_PER_HOUR |  MINS | SUB_TOTAL
    65.00                  |  135    |    146.25
    25.00                  |  120    |    50.00
    65.00                  | NULL  |   NULL
 

This one is almost what I want...

select slip_rate AS RATE_PER_HOUR,ROUND( (
SUM( TIMESTAMPDIFF( 
MINUTE , slip.slip_start, slip.slip_end ) ) )
) AS MINS,ROUND( (
SUM( TIMESTAMPDIFF( 
MINUTE , slip.slip_start, slip.slip_end ) ) /60 ) * slip_rate, 2
) AS TOTAL
FROM slip WHERE project_id=3

The above code returns:

RATE_PER_HOUR |  MINS | TOTAL
    65.00                  |  255    |    276.25
 
As you can see the mins are correct however it is calculating all of them at the 65.00 rate.  All I wish to do is write a simple query that will return 
 
TOTAL
196.25
 
I'm sure I'm close I just haven't messed much with the SUM and TIMESTAMPDIFF function so any help would be greatly appreciated.
 
Thanks in advance,
Twitch

Edited by Twitch
Link to comment
Share on other sites

  • Solution
Ok I knew I was close I guess I just needed some sleep...haha

 

Here is the query that gets what I want in case someone else needs it:



SELECT (
ROUND(SUM(TIMESTAMPDIFF( 
MINUTE , slip_start, slip_end ) /60*slip_rate),2))
 AS TOTAL FROM `slip` WHERE project_id=3


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.