【问题标题】:mysql update with join and countmysql 更新加入和计数
【发布时间】:2011-09-08 20:54:49
【问题描述】:

这个查询有问题。

update table1 as a
left join  (
select count(*) as 'rec' from table2 group by isin having rec<100 )
table2 as h on a.isin=h.isin 
set a.nohist='1' 

我想计算每组的行数,询问他们的计数是否小于 100 并在表 1 中设置一个标志。

我总是出错:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as h on a.isin=h.isin set a.nohist='1'' at line 4

你能帮帮我吗?

谢谢br

【问题讨论】:

    标签: mysql join count


    【解决方案1】:

    您正在将子选择结果的别名设置为table2,然后您将table2“真实化”为h。最重要的是,您尝试通过isin 加入表ha

    如果您希望能够将该表与其他两个表连接起来,则需要在子选择中选择 isin

    【讨论】:

      【解决方案2】:
      update table1 as a
      left join  (
      select count(*) as 'rec' from table2 group by isin having rec<100 )
      -- here you have that error
      

      查看此文档http://dev.mysql.com/doc/refman/5.0/en/join.html

      但是,如果要更新 table1,为什么要执行联接?你想做什么?

      【讨论】:

        【解决方案3】:

        但是,如果要更新 table1,为什么要执行联接?什么 你想做吗?

        我会在 table1 (a.nohist) 上设置一个标志,其中 table2 中每个 isin 少于 100 行(两个表中的键)。

        没有加入有什么原因吗?

        suunto

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-12-16
          • 2014-01-04
          • 2012-06-07
          • 2012-06-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-19
          相关资源
          最近更新 更多