select city, no_orders, upto_two_orders, more_than_two_orders
form (select c.customerid,city,
case
when COUNT(orderid)=0 then 'no_orders'
when COUNT(orderid)<=2 then 'upto_two_orders'
when COUNT(orderid)>2 then 'more_than_two_orders'
end as category
from dbo.Customers as c
left outer join dbo.Orders as o
on c.customerid=o.customerid
group by c.customerid,city) as d
PIOVT(COUNT(customerid) for
category in ([no_orders],[upto_two_orders],[more_than_two_orders])) as p;
请高手帮我看看那里错了,谢谢
两处错误:
第二行的Form应为" From"
倒数第二行的PIOVT应为"PIVOT"
英文差害人不浅,啊········
报什么错?
个人认为
select city, no_orders, upto_two_orders, more_than_two_orders
form (select c.customerid,city,
case
when COUNT(orderid)=0 then 'no_orders'
when COUNT(orderid)<=2 then 'upto_two_orders'
when COUNT(orderid)>2 then 'more_than_two_orders'
end as category
from dbo.Customers as c
left outer join dbo.Orders as o
on c.customerid=o.customerid
group by c.customerid,city) <--在这之前应该没错这后面这个as是给谁附别名为D呢所以这该有错->as d
<--这个地方PIOVT不知道是什么 没见过--> PIOVT(COUNT(customerid) for
category in ([no_orders],[upto_two_orders],[more_than_two_orders])) as p;