【问题标题】:sql query error using INNER JOIN使用INNER JOIN的sql查询错误
【发布时间】:2017-05-31 01:44:10
【问题描述】:

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“FROM tb_users INNER JOIN tb_ph ON tb_ph.username=tb_users.username WHERE tb_ph.r”附近使用正确的语法

我在尝试运行下面的查询时收到上面的错误

UPDATE tb_users 
   SET tb_users.tgh = tb_ph.readygh,
       tb_users.readygh = tb_ph.readygh * 0.25,
       tb_users.profitbalance = tb_ph.readygh - (tb_ph.readygh * 0.25) 
FROM tb_users 
INNER JOIN tb_ph ON tb_ph.username=tb_users.username 
WHERE tb_ph.readygh = tb_ph.paket + (tb_ph.paket*0.6) 
    and tb_users.username=tb_ph.username

如何解决?

【问题讨论】:

    标签: mysql sql inner-join


    【解决方案1】:

    MySQL 中正确的语法是:

    UPDATE tb_users u INNER JOIN
           tb_ph p
           ON p.username = u.username 
        SET u.tgh = p.readygh,
            u.readygh = p.readygh * 0.25, 
            u.profitbalance = p.readygh - (p.readygh * 0.25) 
    WHERE p.readygh = p.paket + (p.paket*0.6);
    

    注意事项:

    • 您的语法是 SQL Server 语法,而不是 MySQL 语法。
    • 表别名使查询更易于编写和阅读。
    • ON 子句和WHERE 子句中都不需要重复连接条件。
    • WHERE 条件非常可疑。通常,您不会对浮点值使用相等,因为非常小的舍入误差可能会使“相等”值无法进行相等比较。

    【讨论】:

      猜你喜欢
      • 2012-11-04
      • 2018-01-27
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 2015-01-10
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多