我是SQL和PHP的新手,并执行我的SQL:
$query = 'SELECT session, id FROM AnalysePageview WHERE session="'.$sessionID.'"ORDER BY id DESC LIMIT 1';
$result = mysqli_query($link, $query);
现在我在这个论坛上看到过这样的事情:
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(description)
from customerrewards
group by description, typeid
order by typeid
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT name,' + @cols + ' from
(
select c.name,
cr.description,
r.typeid
from customers c
left join rewards r
on c.id = r.customerid
left join customerrewards cr
on r.typeid = cr.typeid
) x
pivot
(
count(typeid)
for description in (' + @cols + ')
) p '
execute(@query)
如果我把它放在$ query =“DECLARE @cols中......我会收到错误。
如何在PHP中使用此声明?
答案 0 :(得分:0)