dongxian8858
dongxian8858
2014-01-09 19:25

sql结果,数字作为列标题,如何使用PHP调用或更改用于数据透视的sql列标题

已采纳

I have a pivot table that outputs the following result set: enter image description here

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,

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dqmfo84644 dqmfo84644 7年前

    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
    
    点赞 评论 复制链接分享

相关推荐