0

このT-sqlを使用して、当月の顧客への各販売担当者のカウントを取得します。avg関数を適用して当月の平均訪問数を取得する方法を尋ねたい

SELECT COUNT(VisitTracking.customerID) AS #VISIT, 
       MAX(VisitTracking.visitID) AS VisitID, 
       Customers.title AS Title, 
       Customers.firstName AS [First Name], 
       Customers.LastName AS [Last Name], 
       Company.companyName AS [Company Name], 
       MAX(VisitTracking.DateVisited) AS [Date Visited], 
       CONVERT(DATE, MAX(VisitTracking.nextVisit)) AS [Next Visit], 
       Customers.customerID
FROM VisitTracking 
INNER JOIN Customers ON VisitTracking.customerID = Customers.customerID
INNER JOIN Customer_Company ON Customers.customerID = Customer_Company.customerID     
INNER JOIN Company ON Customer_Company.companyID = Company.companyID
WHERE VisitTracking.DateVisited BETWEEN '11/01/2012'  AND '11/31/2012' 
GROUP BY Customers.title, Customers.firstName, Customers.LastName, Company.companyName, Customers.customerID
4

2 に答える 2

2

コンピューティングを試しましたか?

    SELECT [sParID], count([sParID]) as '#sID'
      FROM [docSVsys]
     group by [sParID]
     order by [sParID] 
   compute avg(count([sParID]))
于 2012-11-30T22:41:22.123 に答える
0

なぜサブセレクトしないのですか?ええ、私は知っています、サブセレクトはNASTYであり、NICEではなく、同様に機能しません。しかし、彼らはレポートや分析のためのデータを作成するときに仕事を成し遂げるので、多分:

SELECT AVG(a.#VISIT) FROM (SELECT COUNT(VisitTracking.customerID) AS #VISIT, 
       MAX(VisitTracking.visitID) AS VisitID, 
       Customers.title AS Title, 
       Customers.firstName AS [First Name], 
       Customers.LastName AS [Last Name], 
       Company.companyName AS [Company Name], 
       MAX(VisitTracking.DateVisited) AS [Date Visited], 
       CONVERT(DATE, MAX(VisitTracking.nextVisit)) AS [Next Visit], 
       Customers.customerID
FROM VisitTracking 
INNER JOIN Customers ON VisitTracking.customerID = Customers.customerID
INNER JOIN Customer_Company ON Customers.customerID = Customer_Company.customerID     
INNER JOIN Company ON Customer_Company.companyID = Company.companyID
WHERE VisitTracking.DateVisited BETWEEN '11/01/2012'  AND '11/31/2012' 
GROUP BY Customers.title, Customers.firstName, Customers.LastName, Company.companyName, Customers.customerID) AS a
于 2012-11-30T21:07:20.493 に答える