Help with WHERE CLAUSE in a query
Posted: Mon Jun 10, 2002 11:24 am
I need some help with a query. The query does the following:
I'm bringing data from hotels. The hotels have rates. I need to bring the last rates of the hotels and shoe them. For so I'm doing this:
SELECT h.ID,h.name,c.name,p.name ,MAX(ht.dateUntil) FROM hotel AS h, city AS c, country AS p, hotelRate AS ht
WHERE h.namee like '%%' AND ht.hotelID = h.ID AND h.cityID = 13 AND c.grupoID = h.cityID AND c.idiomID = 1 GROUP BY h.name ORDER BY h.name ASC, ht.dateUntil DESC
It works, but I want to bring the rates where the later rates are lower than 2002-12-31. For so I did:
SELECT h.ID,h.name,c.name,p.name ,MAX(ht.dateUntil) FROM hotel AS h, city AS c, country AS p, hotelRate AS ht
WHERE h.namee like '%%' AND ht.hotelID = h.ID AND h.cityID = 13 AND c.grupoID = h.cityID AND c.idiomID = 1 AND MAX(ht.dateUntil) <= '2002-12-31' GROUP BY h.name ORDER BY h.name ASC, ht.dateUntil DESC
but I recived the following error.
MySQL said: Invalid use of group function
Am I clear? Can anybody tell me how should the where clause be?
I'm bringing data from hotels. The hotels have rates. I need to bring the last rates of the hotels and shoe them. For so I'm doing this:
SELECT h.ID,h.name,c.name,p.name ,MAX(ht.dateUntil) FROM hotel AS h, city AS c, country AS p, hotelRate AS ht
WHERE h.namee like '%%' AND ht.hotelID = h.ID AND h.cityID = 13 AND c.grupoID = h.cityID AND c.idiomID = 1 GROUP BY h.name ORDER BY h.name ASC, ht.dateUntil DESC
It works, but I want to bring the rates where the later rates are lower than 2002-12-31. For so I did:
SELECT h.ID,h.name,c.name,p.name ,MAX(ht.dateUntil) FROM hotel AS h, city AS c, country AS p, hotelRate AS ht
WHERE h.namee like '%%' AND ht.hotelID = h.ID AND h.cityID = 13 AND c.grupoID = h.cityID AND c.idiomID = 1 AND MAX(ht.dateUntil) <= '2002-12-31' GROUP BY h.name ORDER BY h.name ASC, ht.dateUntil DESC
but I recived the following error.
MySQL said: Invalid use of group function
Am I clear? Can anybody tell me how should the where clause be?