Re: Column grouped by months

2004-11-05 Thread Gleb Paharenko
Hi. Use aliasing. Read carefully comments at http://dev.mysql.com/doc/mysql/en/JOIN.html Scott Hamm <[EMAIL PROTECTED]> wrote: > My current database: > > mysql> SELECT >-> Category.Category, >-> GoalData.Reqvalue, >-> GoalData.GoalMonth >-> FROM >-> goaldat

Re: Column grouped by months

2004-11-05 Thread SGreen
I FORGOT my GROUP BY (arrrgh!) [EMAIL PROTECTED] wrote on 11/05/2004 09:28:20 AM: > You were very close. What you are trying to produce is called a cross-tab > report or a pivot table (depending on who you ask) > > SELECT category.category, > sum(if(goaldata.g

Re: Column grouped by months

2004-11-05 Thread Michael Stassen
Michael Stassen wrote: I can't seem to get to the online manual to check at the moment, but I'd guess that dec is a reserved word. DEC is short for DECIMAL. I should have remembered that. Sigh... Michael -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscri

Re: Column grouped by months

2004-11-05 Thread Michael Stassen
ght syntax to use near 'Dec, I'm running 5.0.1-alpha-nt. -Original Message- From: Michael Stassen [mailto:[EMAIL PROTECTED] Sent: Friday, November 05, 2004 9:42 AM To: Scott Hamm Cc: 'Mysql ' (E-mail) Subject: Re: Column grouped by months I believe you need a self join. Something

RE: Column grouped by months

2004-11-05 Thread Scott Hamm
EMAIL PROTECTED] Sent: Friday, November 05, 2004 9:31 AM To: Scott Hamm Cc: 'Mysql ' (E-mail) Subject: Re: Column grouped by months You're kind of mixing display formatting with data retrieval. MySQL is a database, so it's display options for data are fairly limited, that's

RE: Column grouped by months

2004-11-05 Thread Scott Hamm
- From: Michael Stassen [mailto:[EMAIL PROTECTED] Sent: Friday, November 05, 2004 9:42 AM To: Scott Hamm Cc: 'Mysql ' (E-mail) Subject: Re: Column grouped by months I believe you need a self join. Something like SELECT c.Category, g11.Reqvalue AS Nov, g12.Reqvalue AS Dec FRO

Re: Column grouped by months

2004-11-05 Thread Michael Stassen
I believe you need a self join. Something like SELECT c.Category, g11.Reqvalue AS Nov, g12.Reqvalue AS Dec FROM goaldata g11 JOIN goaldata g12 ON g11.catid = g12.catid AND g11.GoalMonth = 11 AND g12.GoalMonth = 12 JOIN category c ON g11.catid=c.id; This might also work: SELECT

Re: Column grouped by months

2004-11-05 Thread SGreen
You were very close. What you are trying to produce is called a cross-tab report or a pivot table (depending on who you ask) SELECT category.category, sum(if(goaldata.goalmonth=11, reqvalue, 0)) as Nov, sum(if(goaldata.goalmonth=12, reqvalue, 0)) as Dec FROM

Re: Column grouped by months

2004-11-05 Thread Brent Baisley
You're kind of mixing display formatting with data retrieval. MySQL is a database, so it's display options for data are fairly limited, that's usually the job of the front end. But, if you still want to push it to format the way you requested, you need to do a join. Essentially, you're going se