Re: Is this query possible?
From: Scott Gray <gray_at_voicenet.com>
Date: 1996/07/12
Message-ID: <4s5voq$54o_at_omni2.voicenet.com>#1/1
GROUP BY WeekNo, Id
Date: 1996/07/12
Message-ID: <4s5voq$54o_at_omni2.voicenet.com>#1/1
...I appologize if this is a repeat post, but my news server is having problems and I don't know if the last message got posted...
In article <4s378t$jdu_at_tribune.sybase.com>,
Bret Halford <bret_at_sybase.com> wrote:
>Try something like:
>
>select WeekNo, ID, 0.0 Mon, 0.0 Tue, 0.0 Wed, 0.0 Thur, 0.0 Fri into summary_table
>from base_table
>go
>
>update summary_table s set s.Mon = b.Total
>from base_table b
>where
>s.WeekNo = b.WeekNo and
>s.ID = b.ID and
>DayNo = 1
>go
>
>[code for DayNo 2-5 left as exercise for the reader]
Or, for a slightly cooler way of doing it, try...
SELECT WeekNo,
Id, "Mon" = SUM(Total * (1-abs(sign(DayNo - 1)))), "Tue" = SUM(Total * (1-abs(sign(DayNo - 2)))), "Wed" = SUM(Total * (1-abs(sign(DayNo - 3)))), "Thu" = SUM(Total * (1-abs(sign(DayNo - 4)))), "Fri" = SUM(Total * (1-abs(sign(DayNo - 5)))), "Sat" = SUM(Total * (1-abs(sign(DayNo - 6)))), "Sun" = SUM(Total * (1-abs(sign(DayNo - 7))))FROM b
GROUP BY WeekNo, Id
-scott
P.S. Check out the Sybase FAQ in its discussion of characterisic point functions.
-- Scott C. Gray gray_at_voicenet.com Sybase Professional Services scott.gray_at_sybase.com http://www.voicenet.com/~gray/sqsh.htmlReceived on Fri Jul 12 1996 - 00:00:00 CEST