| List: | General Discussion | « Previous MessageNext Message » | |
| From: | Dan Nelson | Date: | May 27 2003 3:03am |
| Subject: | Re: How to write this query pls? | ||
| View as plain text | |||
In the last episode (May 27), Aamir Baig said: > You would figure that an sql query like following would work (I > modified it slightly as it needs to take into account the type > column): > > select P.personid , > SUM(CASE WHEN PH.type = 'PHN' THEN 1 ELSE 0 END) AS PHNC > From Person P left outer join Phone PH > ON P.personid > Where PHNC = 0 group by Phone.personid; > > But it says: > ERROR 1054: Unknown column 'PHNC' in 'where clause' > > I know it's something trivial, can't seem to place the finger at it > though.. You can't use a column alias in the WHERE clause; you'll have to duplicate the SUM expression. See http://www.mysql.com/doc/en/Problems_with_alias.html -- Dan Nelson dnelson@stripped
| Thread | ||
|---|---|---|
| • How to write this query pls? | Titan 160 | 26 May |
| • Re: How to write this query pls? | Becoming Digital | 26 May |
| • RE: How to write this query pls? | Titan 160 | 26 May |
| • Re: How to write this query pls? | Becoming Digital | 26 May |
| • Re: How to write this query pls? | Aamir Baig | 26 May |
| • RE: How to write this query pls? | TheMechE | 26 May |
| • Re: How to write this query pls? | Aamir Baig | 27 May |
| • Re: How to write this query pls? | Dan Nelson | 27 May |
| • Re: How to write this query pls? | Peter Brawley | 27 May |
| • Re: How to write this query pls? | Peter Brawley | 26 May |
| • RE: How to write this query pls? | Titan 160 | 26 May |
