List:General Discussion« Previous MessageNext Message »
From:Chris Date:August 14 2006 2:45am
Subject:Re: Group by with an IF
View as plain text  
Steffan A. Cline wrote:
> I have the following query:
> select *, 
> if( season_week_date = "2006-08-16", "on", "off" ) as stat,
> sum(overall_points) as total_points
> from rosters r 
> left join celebs c 
> on c.celeb_id = r.celeb_id
> where 
> season_id=5062
> and user_id=1
> group by r.celeb_id
> order by overall_rank, ln, fn;
> It almost works as expected however the problem I am concerned about is that
> I never get a stat saying "On" after it resolves. Removing the sum() and
> adding group I get the total_points as expected but now the results are
> always off.

Remove the "if" first and make sure the rest of the query returns the 
results you expect.

That will tell you either the query isn't working the way you want, or 
the if check isn't working.

Is season_week_date only a date or is it a date/time field?

If the query isn't working the way you want, can you post relevant table 
schemas and 5 rows of data from each and what you expect to get?
Group by with an IFSteffan A. Cline13 Aug
  • loggingJosh Milane13 Aug
  • Re: Group by with an IFChris14 Aug
  • Re: Group by with an IFBrent Baisley14 Aug