牛魔王的故事
2018-12-06 18:30:45
??? 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;
請高手幫我看看那里錯了,謝謝
5 回答

郎朗坤
TA貢獻1921條經驗 獲得超9個贊
個人認為
??? 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;
- 5 回答
- 0 關注
- 582 瀏覽
添加回答
舉報
0/150
提交
取消