我有一个名为 Phone_Details 的表,数据如下所示:
Name DeviceType InvoiceDate TotalCharges
Aguilera, Alex Smart Phone 8/3/2012 606.55
Aguilera, Alex Data Card 8/3/2012 26.17
我希望输出为:
Name Total Spend # of devices Avg Spend # of Bills >300
Aguilera, Alex 632.72 2 316.36 1
我试过这样做:
Select Name,Sum(Totalcharges), Count(DeviceType),Sum(Totalcharges)/Count(DeviceType)
from dbo.Phone_Details
group by Name
但是我怎样才能得到最后一列呢?