MySQL Forums
Forum List  »  Newbie

Re: select syntax with condition
Posted by: rui rui
Date: June 10, 2005 12:46AM

Remi Fritzen wrote:
> Sorry here is the complete message :
>
> SELECT sum(t.Cost) AS Cost, sum(t.Duration) AS
> Duration,p.*, c.Name AS ClientName, u.FirstName,
> u.LastName, u.EmailAddress
> FROM tblProjects p
> INNER JOIN tblClients c ON c.ID =
> p.ClientID
> LEFT JOIN tblUsers u ON u.ID = p.Owner
> LEFT JOIN tblTasks t ON t.ProjectID =
> p.ID
> WHERE p.ID = '83' GROUP BY p.ID
>
> I'd like add to add to the sum for the duration
> only when the cost is 0, and keep the sum of the
> cost like that :
>
> so
> ID Cost Duration ....
> 1 0 2
> 2 0 4
> 3 30 5
>
> the result that I'd like to have is
> Cost = 30 and Duration = 6



try adding
WHERE p.ID = '83'
AND sum(t.Cost) = 0
GROUP BY p.ID

Options: ReplyQuote


Subject
Written By
Posted
Re: select syntax with condition
June 10, 2005 12:46AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.