dongyu4908 2018-08-16 11:36
浏览 1376
已采纳

使用LEFT JOIN和LIKE条件的MySQL查询没有显示我的预期

I'm trying to make a query that return data from 4 tables, the problem comes when I try to put some aditional conditions. The query works with 4 tables with LEFT JOIN without the conditions but when I put the LIKE condition nothing change in the result. The result must be the select with "lat" that only begins with 40.95

This code it's working:

if($resultset=getSQLResultSet("SELECT name, lat, lng, description, 
COALESCE(section, 0), COALESCE(AVG(score), 0) FROM places P LEFT JOIN ratings R ON P.id=R.place LEFT JOIN ratings_sections RS ON R.id=RS.rating LEFT JOIN categories C ON P.type=C.type GROUP BY P.name, RS.section ORDER BY P.name, RS.section")){
while ($row = $resultset->fetch_array(MYSQLI_NUM)){
    echo json_encode($row);
    }
}

But nothing change when I put the LIKE condition:

if($resultset=getSQLResultSet("SELECT name,lat, lng, description, COALESCE(section, 0), COALESCE(AVG(score), 0) FROM places P LEFT JOIN ratings R ON P.id=R.place AND P.lat LIKE '40.95%' LEFT JOIN ratings_sections RS ON R.id=RS.rating LEFT JOIN categories C ON P.type=C.type GROUP BY P.name, RS.section ORDER BY P.name, RS.section")){
    while ($row = $resultset->fetch_array(MYSQLI_NUM)){
        echo json_encode($row);
    }
}

Result of the query

  • 写回答

2条回答 默认 最新

  • doushi8599 2018-08-16 11:40
    关注

    The SQL UNION ALL operator is used to combine the result sets of 2 or more SELECT statements.

    SELECT name,lat, lng, description,... FROM
    

    and

    SELECT score FROM
    

    Are different

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面