我有带有列的以下表格图章:

LOC(Blob)
LOCDTL
LOCTIME
CARRIERTYPE
CARRIERID


我想获取与来自查询本身数组中前端的每个id对应的MAX(LOCTIME)值的行。

我已经尝试过这种可能性,但没有一种能达到我想要的效果。

SELECT X(LOC), Y(LOC), LOCDTL, LOCTIME, UPPER(CARRIERTYPE), CARRIERID
FROM  LOC_EVENT_CARRIER_REPO
WHERE UPPER(TRIM(CARRIERTYPE)) = "VESSEL"
  AND UPPER(TRIM(CARRIERID)) IN (35, 69,70,71,72,73,74)
  AND LOCTIME IN (SELECT MAX(LOCTIME) FROM LOC_EVENT_CARRIER_REPO
                  WHERE UPPER(CARRIERTYPE) = "VESSEL"
                    AND CARRIERID IN (35, 69,70,71,72,73,74))
group by CARRIERID;

最佳答案

如果我做对了。找到最后一行,在提供的ID列表中为每个MAX(LOCTIME)加上CARRIERID

SELECT X(LOC), Y(LOC), LOCDTL, LOCTIME, UPPER(CARRIERTYPE), CARRIERID
FROM  LOC_EVENT_CARRIER_REPO e
JOIN (
      SELECT CARRIERID, MAX(LOCTIME) maxlt
      FROM LOC_EVENT_CARRIER_REPO
      WHERE UPPER(CARRIERTYPE) = "VESSEL"
                    AND CARRIERID IN (35, 69,70,71,72,73,74)
      GROUP BY CARRIERID
    ) m ON e.CARRIERID = m.CARRIERID AND e.LOCTIME = m.maxlt

关于mysql - 选择列中具有最大值的所有行作为数组中所有ID的列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57474586/

10-12 19:51