question

Mohammed Al-Ali avatar image
Mohammed Al-Ali asked

How to show the total number of taken quizzes for each division on each month?

Hello everybody, I am developing a training management web-based system which will show the management the training record for each division. My database design is like following: > Employee Table: Username, Name, Job, DivisionID > Division Table: DivisionID, DivisionName > Quiz Table: QuizID, Title, Description > UserQuiz Table: UserQuizID, Score, DateTimeComplete, QuizID, Username **NOTE:** The first attribute in each table is the primary key. The SQL Query that I am using for this task is: SELECT COUNT(DISTINCT dbo.UserQuiz.QuizID) AS [Total Number of Quizzes], dbo.Divisions.DivisionName, dbo.UserQuiz.DateTimeComplete AS [Date] FROM dbo.UserQuiz INNER JOIN dbo.Quiz ON dbo.UserQuiz.QuizID = dbo.Quiz.QuizID INNER JOIN dbo.employee ON dbo.UserQuiz.Username = dbo.employee.Username RIGHT OUTER JOIN dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode GROUP BY dbo.Divisions.DivisionName,dbo.UserQuiz.DateTimeComplete This query shows me something like this: in 12-25-2011 .............. Division A .................. 1 12-27-2011 .............. Division A .................. 1 **And this is wrong. It should sum the number of quizzes for Division A in Dec and so on. How to do that?**
sql-server-2008tsql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
You could change **dbo.UserQuiz.DateTimeComplete** to **CONVERT(varchar(7),UserQuiz.DateTimeComplete,120)** in order to get the date on format YYYY-MM instead of the full DateTime.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.