我的MySQl中有看起来像这样的数据...

|         ProjectUID                   |    dataStartDate    |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-04-14 10:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-02-23 16:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-02-24 08:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-02-24 15:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-02-24 23:30:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-05-24 08:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-11-06 08:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-05-23 08:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-11-03 08:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-05-23 08:00:00 |
| F2EAACC7-607F-E611-91D1-34028608A344 | 2017-11-03 08:00:00 |


我需要将dataStartDate更新为唯一ProjectUID的最早值(在这种情况下,将F2EAACC7-607F各处的ProjectUID:F2EAACC7-607F-E611-91D1-34028608A344更改为dataStartDate“ 2017-02-23 16:00:00” -E611-91D1-34028608A344出现)...
进行此查询可以为我提供最早的价值,并且效果很好........

SELECT ProjectUID, min(dataStartDate) dataStartDate
FROM PPMload_temp
GROUP BY ProjectUID;


当我尝试通过子选择进行更新时,问题就来了。

UPDATE PPMload_temp c
SET c.dataStartDate=x.dataStartDate
FROM
(SELECT ProjectUID, min(dataStartDate) dataStartDate FROM PPMload
GROUP BY ProjectUID) x where c.ProjectUID = x.ProjectUID;


这给出了错误...。


  错误1064(42000):您的SQL语法有错误;检查
  与您的MySQL服务器版本相对应的手册
  在'FROM附近使用的语法(SELECT ProjectUID,min(dataStartDate)
  第1行的dataStartDate FROM PPMload GROUP BY'


关于我要去哪里的任何想法?非常感谢!
JW

最佳答案

您需要使用类似的update-join构造

UPDATE PPMload_temp c
JOIN
(SELECT ProjectUID, min(dataStartDate) dataStartDate FROM PPMload
GROUP BY ProjectUID) x ON c.ProjectUID = x.ProjectUID
SET c.dataStartDate = x.dataStartDate

10-01 23:25