我有这个SQL语句:
SELECT pgdd1.DT_DEPOT AS DT_LAST,pgdd.DT_DEPOT AS DT, pgdd.ETAT AS ETAT, pgtd.NOM_DOCUMENT AS NOM_DOCUMENT
FROM pg_detachements_documents pgdd
LEFT JOIN pg_types_documents pgtd ON pgtd.ID=pgdd.ID_DOCUMENT
LEFT JOIN pg_detachements_documents pgdd1 on pgdd1.ID = pgdd.ID
WHERE pgdd.ID_DETACHEMENT = 4
ORDER BY pgdd.ID
DESC
LIMIT 5
这个工作正常,但当我尝试只显示DT_LAST的第一行时,我得到一个SQL语法错误
我正在尝试这个:
SELECT FIRST(pgdd1.DT_DEPOT) AS DT_LAST,pgdd.DT_DEPOT as DT, pgdd.ETAT AS ETAT, pgtd.NOM_DOCUMENT AS NOM_DOCUMENT
FROM pg_detachements_documents pgdd
LEFT JOIN pg_types_documents pgtd ON pgtd.ID=pgdd.ID_DOCUMENT
LEFT JOIN pg_detachements_documents pgdd1 on pgdd1.ID = pgdd.ID
WHERE pgdd.ID_DETACHEMENT = 4 and pgdd1.DT_DEPOT = pgdd.DT_DEPOT
ORDER BY pgdd.ID
DESC
LIMIT 5
我尝试使用where pgdd1.DT_DEPOT in (same first select but with limit 1)
,但我的SQL服务器说他不支持内部选择限制。
我只想在所有行中首先(DT_LAST值)。
我的最终目标是在这种情况下按元素选择组的第一组行,其中DT是相同的前两行。