R
R
Romario212018-11-23 11:51:36
SQL Server
Romario21, 2018-11-23 11:51:36

SQL query: count count with sort?

I'm doing a period report.
Within a month, the manager makes sales to the client.
You need to count the number of sales for which only the date of the first sale falls within the beetween range.
For example:
The first sale to a customer happened in October. Follow-up in November.
When making a report for November, I should get 0, and when making a report for October, I should get 1.

SELECT contact.Id AS ID,contact.Name AS MANAGER_NAME,
department.Name AS DEPARTMENT,
(SELECT COUNT(Id) FROM Opportunity 
WHERE  StageId='60d5310c-5be6-df11-971b-001d60e938c6' 
 AND OwnerId=contact.Id 
 AND  UsrDATEFinansirovanieVydano BETWEEN  '2018-02-01' AND '2018-11-23') AS ACCOUNT_ZAPUSK
FROM Contact contact  JOIN Department department ON contact.DepartmentId= department.Id

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question