我创建了这个 T-Sql 查询来给我多少次客户访问并按公司分组我的 Pronlem 是我的查询不要只计算一次访问也不按公司分组
SELECT COUNT( VisitTracking.customerID) AS #VISIT
, MAX(VisitTracking.visitID) AS visitID
,Customers.title AS Title
,Customers.customerID
,Customers.firstName AS "First Name"
,Customers.LastName AS "Last Name"
,Company.companyName AS "Company Name"
,VisitTracking.DateVisited AS "Date Visited"
,VisitTracking.nextVisit AS "Next Visit"
FROM VisitTracking INNER JOIN
Customers ON VisitTracking.customerID = Customers.customerID INNER JOIN
Company ON VisitTracking.companyID = Company.companyID
GROUP BY VisitTracking.companyID,Customers.customerID, VisitTracking.customerID, Customers.title, Customers.firstName, Customers.LastName, Company.companyName, VisitTracking.DateVisited,VisitTracking.nextVisit
输出
我想要的是
2 29 Mr 2 Mike Mike N/A 2013-01-31
1 28 Mr 2 Mike Mike Compudata 2013-01-31