sql结果,数字作为列标题,如何使用PHP调用或更改用于数据透视的sql列标题
问题描述:
I have a pivot table that outputs the following result set:
as you can see column names are 0.9,1.2,1.5 etc etc
in my php, I cant reference the number
echo $order->a;
I get error:Parse error: syntax error, unexpected T_DNUMBER, expecting T_STRING or T_VARIABLE
How can I correctly fetch this column or perhaps adjust the sql to have an alias? like a or b? like:
select * from t pivot ( avg(stock) for length in ([0.9] as a, [1.2] as b)) piv
Thanks as always,
答
If you want to alias your columns then you would have to use something like the following, where you place your alias in the final select list:
select section,
[0.9] as a,
[1.2] as b
from t
pivot
(
avg(stock)
for length in ([0.9], [1.2])
) piv