Re: Problem with SQL query
| From: | Alberto Serra | Date: | Sun, 07 Jul 2002 09:56:43 +0000 |
| Subject: | Re: Problem with SQL query | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-105942@lists.php.net to get a copy of this message | ||
Привет!
I forgot to add:
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
I take it that you have a *monthly_view* column in your table that is not the *monthly_views* alias yoiu use in your query. if that's a typo and you mean to order by the numebr of visitors (that is, you want the most visited month on top of the result) your query should probably look like:
SELECT
extract('year', time),
extract('month', time),
count(*) as monthly_views
FROM
visitors
group by
extract('year', time),
extract('month', time)
order by
3 desc
limit 1
That's because most databases (and I guess MySql is no exception) will not be able to use an alias in their GROUP BY, ORDER BY clauses. But you may want to try, maybe MySql *is* an exception, after all.
пока
Альберто
Киев
--
@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@
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.......