Re: Problem with SQL query
| From: | Alberto Serra | Date: | Sun, 07 Jul 2002 09:48:36 +0000 |
| Subject: | Re: Problem with SQL query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-105941@lists.php.net to get a copy of this message | ||
Привет!
I can't figure out what is wrong with this: $query = "select count(*) as monthly_views from visitors group by extract('year', time), extract('month', time) order by monthly_view desc limit 1";AFAIK this is no ANSI SQL, which is why is not portable. Your query should really be SELECT extract('year', time), extract('month', time) count(*) as monthly_views FROM visitors group by extract('year', time), extract('month', time) order by monthly_view desc limit 1 *BUT* extract doesn't seem to be a MYSQL function, you most probably need to use DATE_FORMAT. Look in the Mysql docs for this. As a general ANSI rule group by functions *need* the fields on which result is grouped to appear *first* in the query. Take half an hour to look at the GROUP BY docs in MySQL online manual, everything will become much clearer. пока Альберто Киев -- @-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@ LoRd, CaN yOu HeAr Me, LiKe I'm HeArInG yOu? lOrD i'M sHiNiNg... YoU kNoW I AlMoSt LoSt My MiNd, BuT nOw I'm HoMe AnD fReE tHe TeSt, YeS iT iS ThE tEsT, yEs It Is tHe TeSt, YeS iT iS ThE tEsT, yEs It Is.......