我正在尝试运行这个查询(在 Heidi sql 中工作),但我无法通过 php 在我的网站上运行它。
$ID_CARTERA= $_GET['id'];
$result = mysql_query("
SELECT K.Date_as_of,
K.Fund_Name,
K.Fund_Benchmark_name,
K.Class_Name,
K.Special_Class_Name,
ROUND(sum(case K.Column_ID
when 1 then K.Fund_Yield
else 0
end ), 2) 'Fund 1 Mes %',
ROUND(sum(case K.Column_ID
when 2 then K.Fund_Yield
else 0
end ), 2) 'Fund 6 Meses %',
ROUND(sum(case K.Column_ID
when 5 then K.Fund_Yield
else 0
end ), 2) 'Fund Año Corrido %',
ROUND(sum(case K.Column_ID
when 3 then K.Fund_Yield
else 0
end ), 2) 'Fund 1 Año %',
ROUND(sum(case K.Column_ID
when 4 then K.Fund_Yield
else 0
end ), 2) 'Fund 2 Años %',
ROUND(sum(case K.Column_ID
when 1 then K.Fund_Benchmark_Yield
else 0
end ),
FROM (select
DATE_FORMAT(A.F_HASTACORTE, '%d/%m/%Y') 'Date_as_of',
D.DES_CARTERA_CC Fund_Name,
G.DES_CARTERA_CC Fund_Benchmark_name,
B.DES_CARTERACLASE Class_Name,
C.DES_CARTERACLASE_ESP Special_Class_Name,
H.ID_COLUMNA Column_ID,
H.DES_COLUMNA Column_labels,
A.POR_RENTCARTERA Fund_Yield,
A.POR_RENTBENCH Fund_Benchmark_Yield,
I.POR_RENTCLASE Class_Yield,
J.POR_RENTCLASEESP Special_Class_Yield,
A.POR_RENTMENOSBENCH Plus_Minus_Fund_Benchmark,
A.POR_RENTMENOSCLASE Plus_Minus_Class,
A.POR_RENTMENOSCLASEESP Plus_Minus_Special_Class,
A.POR_PERCENTILCLASE Percentile_Class,
A.POR_PERCENTILCLASEESP Percentile_Special_Class
FROM dr_rentmovil_carteras A
JOIN mcarteras D ON ( A.ID_CARTERA = D.ID_CARTERA )
JOIN mcarteras_clases B ON ( D.ID_CARTERACLASE = B.ID_CARTERACLASE )
JOIN mcarteras_clasesesp C ON ( D.ID_CARTERACLASE_ESP = C.ID_CARTERACLASE_ESP )
JOIN mpaises E ON ( A.F_HASTACORTE = E.F_ULT_CIERRE_DIARIO)
JOIN det_refcru_carterasbench F ON ( A.ID_CARTERA = F.ID_CARTERA )
JOIN mcarteras G ON ( F.ID_CARTERABENCH = G.ID_CARTERA )
JOIN dformatos H ON ( A.ID_COLUMNA = H.ID_COLUMNA )
JOIN dr_rentmovil_clases I ON ( A.ID_COLUMNA = I.ID_COLUMNA AND E.F_ULT_CIERRE_DIARIO = I.F_HASTACORTE and B.ID_CARTERACLASE = I.ID_CARTERACLASE )
JOIN dr_rentmovil_clasesesp J ON ( A.ID_COLUMNA = J.ID_COLUMNA AND E.F_ULT_CIERRE_DIARIO = J.F_HASTACORTE and C.ID_CARTERACLASE_ESP = J.ID_CARTERACLASE_ESP )
WHERE A.ID_CARTERA = $ID_CARTERA ) K
")
or die(mysql_error());
这是我得到的错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (select DATE_FORMAT(F_ULT_CIERRE_MENSUAL, '%d/%m/%Y') 'Datos' at line 30
我一直无法缩小问题的范围。