MySQL Forums
Forum List  »  Newbie

Re: Grouping by a date period.
Posted by: Felix Geerinckx
Date: August 19, 2005 11:56AM

R A wrote:

> Unfortunately, in my case, the date period could change at any time as it is user defined

Using the period idea, but without a fixed calendar:

SET @d := 15; # Start day of a monthly period
SELECT
CASE
WHEN DAY(pabx.dt) < @d THEN MONTH(pabx.dt) - 1
WHEN DAY(pabx.dt) >= @d THEN MONTH(pabx.dt)
END as period,
pabx.extension,
SUM(pabx.cost)
FROM pabx
GROUP BY period, pabx.extension;

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
R A
August 19, 2005 07:50AM
R A
August 19, 2005 08:13AM
R A
August 19, 2005 09:21AM
R A
August 19, 2005 11:29AM
Re: Grouping by a date period.
August 19, 2005 11:56AM
R A
August 19, 2005 12:18PM


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.