我正在尝试创建一个View,它从Logs(Registro tracto和registro Operador)绘制最后一个条目,对应于LoadOrder(Orden de carga)的行程(viaje)并显示每个'带有信息的加载顺序'{ {3}}
我已经勾画了下一个视图,但由于Sytaxis错误,我无法使其正常工作。
`CREATE VIEW `OrdenEnCurso` AS
SELECT OC.'NO_ORDEN_DE_CARGA' AS 'ORDEN DE CARGA'
, OC.'ID_VIAJE' AS 'ID DE VIAJE'
, RT.'TRACTO_ECO' AS 'TRACTO'
, ROO.'NOMBRE' AS 'N.OPERADOR',
GF.S AS 'GASTOS FINANCIADOS'
FROM
'ORDEN_DE _CARGA' AS OC
INNER JOIN (SELECT 'TRACTO_ECO','ID_VIAJE' FROM 'REGISTRO_TRACTO' GROUP BY
'ID_VIAJE' HAVING MAX('FECHAHORA') ) AS RT
ON OC.ID_VIAJE=RT.ID_VIAJE
INNER JOIN (SELECT CONCAT_WS(',',O.AP_PAT,O.AP_MAT,O.NOMBRE) AS 'NOMBRE'
FROM 'OPERADOR' AS O
INNER JOIN (SELECT 'ID_VIAJE','NO_OPERADOR' FROM 'REGISTRO_OPERADOR'
GROUP BY 'ID_VIAJE' HAVING MAX('FECHAHORA') ) AS RO
ON RO.NO_OPERADOR=O.NO_OPERADOR) AS ROO
ON OC.ID_VIAJE=ROO.ID_VIAJE
INNER JOIN (SELECT 'OC',SUM(IMPORTE) AS S FROM 'GASTOS_F_CLIENTE'
GROUP BY
'NO_ORDEN_DE_CARGA') AS GF ON OC.NO_ORDEN_DE_CARGA=GF.OC;
另外,正如您所看到的,我想将运算符名称与昏迷联系起来。最后总结客户将为每个LoadOrder支付额外费用。
错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在''NO_ORDEN_DE_CARGA'AS'ORDEN DE CARGA'附近使用正确的语法,OC.'ID_VIAJE'AS'ID DE VIAJE',R'在第2行0.000秒
答案 0 :(得分:0)
您对使用刻度线和引号感到困惑
尝试此SQL语句
CREATE VIEW OrdenEnCurso AS
SELECT OC.NO_ORDEN_DE_CARGA AS `ORDEN DE CARGA`,
OC.ID_VIAJE AS `ID DE VIAJE`,
RT.TRACTO_ECO AS TRACTO,
ROO.NOMBRE AS `N.OPERADOR`,
GF.S AS `GASTOS FINANCIADOS`
FROM ORDEN_DE_CARGA AS OC
INNER JOIN (
SELECT TRACTO_ECO, ID_VIAJE
FROM REGISTRO_TRACTO
GROUP BY ID_VIAJE
HAVING MAX(FECHAHORA)
) AS RT
ON OC.ID_VIAJE = RT.ID_VIAJE
INNER JOIN (
SELECT CONCAT_WS(`,`,O.AP_PAT,O.AP_MAT,O.NOMBRE) AS NOMBRE
FROM OPERADOR AS O
INNER JOIN (
SELECT ID_VIAJE, NO_OPERADOR
FROM REGISTRO_OPERADOR
GROUP BY ID_VIAJE
HAVING MAX(FECHAHORA)
) AS RO
ON RO.NO_OPERADOR=O.NO_OPERADOR
) AS ROO
ON OC.ID_VIAJE=ROO.ID_VIAJE
INNER JOIN (
SELECT OC,SUM(IMPORTE) AS S
FROM GASTOS_F_CLIENTE
GROUP BY NO_ORDEN_DE_CARGA
) AS GF
ON OC.NO_ORDEN_DE_CARGA=GF.OC;