我一直在尝试执行下面的代码,但它没有运行。 SQLFiddle提供
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第2行
'.'EO' AS 'EO','EF'.'AC' AS 'AC','EO''
附近使用正确的语法
我不知道我做错了什么。
SELECT DISTINCT
'EO'.'EO' AS 'EO',
'EF'.'AC' AS 'AC',
'EO'.'WO' AS 'WO',
'EO'.'WOF' AS 'WOF',
'EF'.'PN_SN' AS 'PN_SN',
'EC'.'CD' AS 'CD',
'EF'.'PN' AS 'PN',
'EO'.'EOC' AS 'EOC',
'EO'.'STAT' AS 'STAT',
'EF'.'OVRD' AS 'OVRD',
'EF'.'SEL' AS 'SEL',
'EF'.'ED' AS 'ED',
'EF'.'SCHED' AS 'SCHED',
'EF'.'SAD' AS 'SAD',
'EF'.'SA' AS 'SA',
'EO'.'EOD' AS 'EOD'
FROM
EO,
EC,
EF
WHERE
(
'EO'.'EO' = 'EC'.'EO'
)
AND
(
'EF'.'PSN' = 'EC'.'PSN'
)
AND
(
'EO'.'WB' = 'Y'
)
AND
(
'EC'.'CONT' = 'W & B'
)
;
SELECT
'EC'.'RSTD' AS 'RSTD'
FROM EC RIGHT JOIN EF
ON ( 'EF'.'EO' = 'EC'.'EO' )
ON ( 'EF'.'AC' = 'EC'.'AC' )
ON ( 'EF'.'PN' = 'EC'.'PN' )
ON ( 'EF'.'PSN' = 'EC'.'PSN' )
答案 0 :(得分:0)
单引号 - '
- 适用于文字。使用双引号 - "
- 用于标识符...
SELECT
"EC"."RSTD"
FROM EC RIGHT JOIN EF
ON ( "EF"."EO" = "EC"."EO" )
ON ( "EF"."AC" = "EC"."AC" )
ON ( "EF"."PN" = "EC"."PN" )
ON ( "EF"."PSN' = "EC"."PSN" )
......或者更好的是,完全省略它们:
SELECT
EC.RSTD
FROM EC RIGHT JOIN EF
ON ( EF.EO = EC.EO )
ON ( EF.AC = EC.AC )
ON ( EF.PN = EC.PN )
ON ( EF.PSN = EC.PSN )
显然,在适当时保留单引号,例如将列与文字进行比较:
where EO.WB = 'Y'
另请注意,在不更改列名时不必使用列别名:select ec.rstd as rstd
是多余的,实际上很烦人。保留用于重命名列的用途,例如select ec.rstd as my_new_col_name