我正在尝试在PHP中实现pivot方法,但它给出了一些错误。
表格为clientdetails
,包含3个属性(clientname
,productname
,quantity
)。
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("HR") or die(mysql_error());
$sql=mysql_query("select clientname, 'Software' as s, 'Desktop' as d
FROM (
select clientname,productname,quantity
FROM clientdetails)
as p pivot (Sum(quantity) for productname in ('Software' ,'Desktop'))") 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 'pivot (Sum(quantity) for productname in ('Software' ,'Desktop'))' at line 5 ".