我有以下PHP查询执行MySQL查询而没有错误但是最后忽略了查询的城市部分?有没有办法安排AND / OR语句?
$sql_query = "SELECT ListOfficeMLSID AS list_office_mlsid, MLSNumber AS mls_number, City AS city, ListPrice AS list_price FROM my_table WHERE ListOfficeMLSID =\"office6\" OR ListOfficeMLSID =\"office7\" OR ListOfficeMLSID =\"office2\" AND ListPrice >= 1500000 AND city = \"Bonita Springs\" OR city = \"Estero\"";
答案 0 :(得分:2)
$sql_query = "SELECT ListOfficeMLSID AS list_office_mlsid, MLSNumber AS mls_number, City AS city, ListPrice AS list_price FROM my_table WHERE ListOfficeMLSID IN('office6','office7','office2') AND ListPrice >= 1500000 AND city IN('Bonita Springs', 'Estero')";
答案 1 :(得分:1)
$sql_query = "SELECT ListOfficeMLSID AS list_office_mlsid, MLSNumber AS mls_number, City AS city, ListPrice AS list_price FROM my_table WHERE (ListOfficeMLSID =\"office6\" OR ListOfficeMLSID =\"office7\" OR ListOfficeMLSID =\"office2\") AND ListPrice >= 1500000 AND (city = \"Bonita Springs\" OR city = \"Estero\")";
根据我的理解,你想获得(office2,office6或office6)和ListPrice> = 1500000 AND城市(Bonita Springs或Estero)的ListOfficeMLSID记录?
您的查询将返回至少符合您的一个条件的记录