用于按maxprice转换货币和排序的Mysql查询

用于按maxprice转换货币和排序的Mysql查询,mysql,Mysql,我有一个和SQL查询,它根据价格对属性进行排序,但是当我添加and IF子句时,它会抛出一个错误。这是我的问题 SELECT pp_propertylisting.id AS pid, pp_propertylisting.title, pp_propertylisting.city, pp_propertylisting.street, pp_propertylisting.country, pp_propertylisting.bedrooms, pp_p

我有一个和SQL查询,它根据价格对属性进行排序,但是当我添加and IF子句时,它会抛出一个错误。这是我的问题

SELECT pp_propertylisting.id AS pid,
   pp_propertylisting.title,
   pp_propertylisting.city,
   pp_propertylisting.street,
   pp_propertylisting.country,
   pp_propertylisting.bedrooms,
   pp_propertylisting.bathrooms,
   pp_propertylisting.termsconditions,
   pp_propertyprice.currency,
   pp_propertyimage.imageurl,
   IF(pp_propertyprice.currency='dollar',Max(pp_propertyprice.pricepernight)*0.5,Max(pp_propertyprice.pricepernight)) AS maxiprice,
   pp_propertyimage.title AS imgtitle,
   pp_propertyprice.begindate,



(SELECT max(pp_propertyprice.pricepernight)
 FROM pp_propertyprice
 WHERE pp_propertyprice.propertyid = pp_propertylisting.id) AS maxprice,
   pp_propertyprice.enddate,
   pp_propertylisting.latitude,
   pp_propertylisting.longitude,
   pp_propertylisting.property_maxpeople,
   pp_propertylisting.size,
   pp_propertylisting.buildingsize,
   pp_propertylisting.slug,
   pp_propertylisting.cityslug,
   pp_propertylisting.countryslug,
   pp_propertylisting.continentslug,
   pp_propertylisting.regionslug
   FROM pp_propertyimage,
   pp_propertylisting,
   pp_propertyuntidetails1,
   pp_propertyprice
   WHERE pp_propertyuntidetails1.propertyid = pp_propertylisting.id
   AND pp_propertylisting.id = pp_propertyimage.propertyid
   AND pp_propertyimage.recordlistingid = 1
   AND pp_propertylisting.archivestatus = 0
   AND pp_propertyimage.delstatus = 0
   AND pp_propertyprice.propertyid = pp_propertylisting.id
   AND pp_propertylisting.delstatus=0
   AND pp_propertylisting.approvestatus = 1
   GROUP BY pp_propertylisting.id
   ORDER BY maxprice DESC,
     pp_propertylisting.title DESC HAVING maxiprice > 0
   AND maxiprice < 5000
您能告诉我为什么会出现语法错误吗。

having子句位于group by之后,order by之前:


您能添加错误消息吗?Maxpp_propertyprice.pricepernight*0.5您是指Maxpp_propertyprice.pricepernight*0。5@jens1064-您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解在第行的“GROUP BY pp_PropertyList.id ORDER BY maxprice DESC,pp_PropertyList.title”附近使用的正确语法1@Abhik是的,我已经改正了Hanks Gordon,成功了。。不知道我为什么不试试这个
SELECT . . .
GROUP BY pp_propertylisting.id
HAVING maxiprice > 0 AND maxiprice < 5000
ORDER BY maxprice DESC, pp_propertylisting.title DESC