Question

I have a table like this;

Date                 URL                    
02/01/2014 12:10:55  /myservice/mypage
02/01/2014 15:04:50  /myservice/mypage
02/01/2014 03:02:25  /myservice/anotherpage
02/02/2014 01:08:55  /myservice/mypage
02/02/2014 16:09:50  /myservice/mypage
02/02/2014 18:08:05  /myservice/mypage
02/02/2014 03:06:11  /myservice/mypage

I would like to query the table to get the total calls per day and the number of unique calls per day, like this;

MyService Results

Date        Unique Calls      Total Calls
02/01/2014   2                 3
02/02/2014   1                 4

I am new to SQL and can't figure this out. Thanks for any help

Was it helpful?

Solution

Try this.

SELECT CONVERT(DATE, t.Date, 101) DATE,
    COUNT(t.URL) [Total Calls],
    COUNT(DISTINCT t.URL) [Unique Calls]
FROM Table t
GROUP BY CONVERT(DATE, t.Date, 101)

OTHER TIPS

You could try the following: Where MyTable is the table where the records are stored and Date and URL are the columns you mentioned.

SELECT
  CAST([Date] AS Date) AS [Date]
 ,COUNT(DISTINCT URL) AS [Unique Calls]
 ,COUNT(URL) AS [Total Calls]
FROM MyTable
GROUP BY CAST([Date] AS Date)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top