MS 查询如何使用别名 (excel odbc) 内部连接 2 个表
MSQuery how to inner join 2 tables with allias (excel odbc)
我一直试图获取每个 ean (id) 的最后一行,因为它有多个时间戳 (tmh),但我无法在带有 ODBC conexions 的 MSQuery 上获取它...有人建议吗?
SELECT TMH, PESO, ALTO, ANCHO, LARGO, EAN FROM
(SELECT TMH219 as TMH, PES219 AS PESO, ALT219 AS ALTO, ANC219 AS ANCHO, LAR219 AS LARGO, EAN219 AS EAN FROM SGAVDL.SGA21900) T1
INNER JOIN (SELECT EAN219, MAX(TMH219) FROM SGAVDL.SGA21900) T2
ON T1.EAN219 = T2.EAN219
GROUP BY TMH, PESO, ALTO, ANCHO, LARGO, EAN
提前致谢!
使用下面的查询你应该得到
SELECT T1.TMH219 as TMH, PES219 AS PESO, ALT219 AS ALTO, ANC219 AS ANCHO, LAR219 AS LARGO, T1.EAN219 AS EAN FROM
SGAVDL.SGA21900 T1 INNER JOIN (SELECT MAX(TMH219) TMH219 FROM SGAVDL.SGA21900) T2
ON T1.TMH219=T2.TMH219
我可以用简单的方法解决它,我没有按第二个 table t2 分组,我也没有把 TMH 的相等性放在 ON 参数中:
SELECT T2.MTMH, T1.PESO, T1.ALTO, T1.ANCHO, T1.LARGO, T1.EAN FROM
(SELECT TMH219 as TMH, PES219 AS PESO, ALT219 AS ALTO, ANC219 AS ANCHO, LAR219 AS LARGO, EAN219 AS EAN FROM SGAVDL.SGA21900) T1
RIGHT JOIN
(SELECT EAN219, MAX(TMH219) AS MTMH FROM SGAVDL.SGA21900
WHERE DATE(TMH219) = DATE(CURRENT_DATE) GROUP BY EAN219) T2
ON T1.EAN = T2.EAN219 and t1.TMH = T2.MTMH
GROUP BY EAN, MTMH, PESO, ALTO, ANCHO, LARGO
我认为这或多或少是@Stanislovas 的意思,但他简化得很好
谢谢!
我一直试图获取每个 ean (id) 的最后一行,因为它有多个时间戳 (tmh),但我无法在带有 ODBC conexions 的 MSQuery 上获取它...有人建议吗?
SELECT TMH, PESO, ALTO, ANCHO, LARGO, EAN FROM
(SELECT TMH219 as TMH, PES219 AS PESO, ALT219 AS ALTO, ANC219 AS ANCHO, LAR219 AS LARGO, EAN219 AS EAN FROM SGAVDL.SGA21900) T1
INNER JOIN (SELECT EAN219, MAX(TMH219) FROM SGAVDL.SGA21900) T2
ON T1.EAN219 = T2.EAN219
GROUP BY TMH, PESO, ALTO, ANCHO, LARGO, EAN
提前致谢!
使用下面的查询你应该得到
SELECT T1.TMH219 as TMH, PES219 AS PESO, ALT219 AS ALTO, ANC219 AS ANCHO, LAR219 AS LARGO, T1.EAN219 AS EAN FROM
SGAVDL.SGA21900 T1 INNER JOIN (SELECT MAX(TMH219) TMH219 FROM SGAVDL.SGA21900) T2
ON T1.TMH219=T2.TMH219
我可以用简单的方法解决它,我没有按第二个 table t2 分组,我也没有把 TMH 的相等性放在 ON 参数中:
SELECT T2.MTMH, T1.PESO, T1.ALTO, T1.ANCHO, T1.LARGO, T1.EAN FROM
(SELECT TMH219 as TMH, PES219 AS PESO, ALT219 AS ALTO, ANC219 AS ANCHO, LAR219 AS LARGO, EAN219 AS EAN FROM SGAVDL.SGA21900) T1
RIGHT JOIN
(SELECT EAN219, MAX(TMH219) AS MTMH FROM SGAVDL.SGA21900
WHERE DATE(TMH219) = DATE(CURRENT_DATE) GROUP BY EAN219) T2
ON T1.EAN = T2.EAN219 and t1.TMH = T2.MTMH
GROUP BY EAN, MTMH, PESO, ALTO, ANCHO, LARGO
我认为这或多或少是@Stanislovas 的意思,但他简化得很好
谢谢!