Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7057999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:03:37+00:00 2026-05-28T04:03:37+00:00

I am developing a web application for a comapny. This application provides the users

  • 0

I am developing a web application for a comapny. This application provides the users with quizzes. Now, I need to develop a powerful and meaningful dashboard to the management. The dashboard must show many statistics. They want me to design this dashboard in a such way that shows: show % participation = number of quizzes done divided by total number of quizzes on a monthly basis at department level and compare each division.

The question is: I have the following database design:

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 trying to use for showing the results in the last three months is:

SELECT COUNT(DISTINCT dbo.UserQuiz.QuizID) AS [Total Number of Quizzes],  
       dbo.Divisions.DivisionName,
       DATENAME(Month, dbo.UserQuiz.DateTimeComplete) AS Month 
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, 
   DATENAME(Month, dbo.UserQuiz.DateTimeComplete)

Also, I tried many queries and each time got something different from what I want. Frankly, I don’t have any idea about how to get the above requirement.

EDIT:
Here is the schema with some data:

    /****** Object:  Table [dbo].[Divisions]    Script Date: 01/15/2012 12:29:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Divisions](
    [SapCode] [float] NOT NULL,
    [DivisionShortcut] [varchar](10) NOT NULL,
    [DivisionName] [varchar](max) NOT NULL,
 CONSTRAINT [PK_Divisions] PRIMARY KEY CLUSTERED 
(
    [SapCode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30003143, N'PMOD', N'AB')
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30003144, N'ESD', N'BC')
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30003153, N'PESD', N'CD')
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30003158, N'SSD', N'DE')
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30012601, N'PEOD', N'EF')
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30021812, N'PEMD', N'FG')
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30021876, N'BAG', N'GH
')
INSERT [dbo].[Divisions] ([SapCode], [DivisionShortcut], [DivisionName]) VALUES (30023176, N'EPM', N'HI')
/****** Object:  Table [dbo].[Quiz]    Script Date: 01/15/2012 12:29:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Quiz](
    [QuizID] [int] IDENTITY(1,1) NOT NULL,
    [Title] [varchar](max) NOT NULL,
    [IsSent] [bit] NOT NULL,
    [Description] [varchar](max) NULL,
 CONSTRAINT [PK_Quiz] PRIMARY KEY CLUSTERED 
(
    [QuizID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Quiz] ON
INSERT [dbo].[Quiz] ([QuizID], [Title], [IsSent], [Description]) VALUES (11, N'Safety Quiz 1', 0, N'General Safety Quiz')
INSERT [dbo].[Quiz] ([QuizID], [Title], [IsSent], [Description]) VALUES (12, N'Safety Quiz 2', 0, N'General Safety Quiz')
INSERT [dbo].[Quiz] ([QuizID], [Title], [IsSent], [Description]) VALUES (13, N'Safety Quiz 3', 0, N'TEST')
INSERT [dbo].[Quiz] ([QuizID], [Title], [IsSent], [Description]) VALUES (14, N'Safety Quiz 4', 0, N'TEST')
SET IDENTITY_INSERT [dbo].[Quiz] OFF
/****** Object:  Table [dbo].[employee]    Script Date: 01/15/2012 12:29:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[employee](
    [Name] [nvarchar](max) NOT NULL,
    [Username] [nvarchar](255) NOT NULL,
    [JobTitle] [nvarchar](max) NOT NULL,
    [BadgeNo] [float] NOT NULL,
    [EmpOrgType] [float] NOT NULL,
    [DivisionCode] [float] NOT NULL,
 CONSTRAINT [PK_employee] PRIMARY KEY CLUSTERED 
(
    [Username] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'John', N'AGUILEBS', N'Engineering Technician', 9545246, 2, 30012601)
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'TED', N'ALKHATHI', N'Technical Clk Engrg', 8016951, 2, 30012601)
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'Bel', N'ALMARHMS', N'Business Sys Analyst Iv', 289589, 1, 30012601)
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'Tony', N'GRIGFW0A', N'Business Sys Analyst I', 9395990, 2, 30012601)
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'Maria', N'KHWAILAM', N'Asst Engineer Ii', 431177, 2, 30012601)
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'Johny', N'SALEMS0M', N'Business Sys Analyst Iii', 431163, 2, 30003143)
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'Teddy', N'TOWAAH0A', N'Business Sys Analyst Iv', 8819001, 2, 30003143)
INSERT [dbo].[employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (N'Arnold', N'VILLAV0A', N'Asst Engineer I', 329398, 1, 30023176)
/****** Object:  Table [dbo].[UserQuiz]    Script Date: 01/15/2012 12:29:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserQuiz](
    [UserQuizID] [int] IDENTITY(1,1) NOT NULL,
    [QuizID] [int] NOT NULL,
    [DateTimeComplete] [smalldatetime] NOT NULL,
    [Score] [float] NOT NULL,
    [Username] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_UserQuiz] PRIMARY KEY CLUSTERED 
(
    [UserQuizID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[UserQuiz] ON
INSERT [dbo].[UserQuiz] ([UserQuizID], [QuizID], [DateTimeComplete], [Score], [Username]) VALUES (21, 11, CAST(0x9FCD0345 AS SmallDateTime), 0, N'ALMARHMS')
INSERT [dbo].[UserQuiz] ([UserQuizID], [QuizID], [DateTimeComplete], [Score], [Username]) VALUES (81, 11, CAST(0x9FD50288 AS SmallDateTime), 0, N'ALMARHMS')
INSERT [dbo].[UserQuiz] ([UserQuizID], [QuizID], [DateTimeComplete], [Score], [Username]) VALUES (82, 11, CAST(0x9FC80000 AS SmallDateTime), 100, N'TOWAAH0A')
INSERT [dbo].[UserQuiz] ([UserQuizID], [QuizID], [DateTimeComplete], [Score], [Username]) VALUES (83, 12, CAST(0x9FCE0000 AS SmallDateTime), 100, N'ALMARHMS')
INSERT [dbo].[UserQuiz] ([UserQuizID], [QuizID], [DateTimeComplete], [Score], [Username]) VALUES (84, 11, CAST(0x9E790000 AS SmallDateTime), 50, N'VILLAV0A')
INSERT [dbo].[UserQuiz] ([UserQuizID], [QuizID], [DateTimeComplete], [Score], [Username]) VALUES (85, 12, CAST(0x9FC20000 AS SmallDateTime), 100, N'ALMARHMS')
SET IDENTITY_INSERT [dbo].[UserQuiz] OFF
/****** Object:  Default [DF_Quiz_IsSent]    Script Date: 01/15/2012 12:29:48 ******/
ALTER TABLE [dbo].[Quiz] ADD  CONSTRAINT [DF_Quiz_IsSent]  DEFAULT ((0)) FOR [IsSent]
GO
/****** Object:  ForeignKey [FK_employee_Divisions]    Script Date: 01/15/2012 12:29:48 ******/
ALTER TABLE [dbo].[employee]  WITH CHECK ADD  CONSTRAINT [FK_employee_Divisions] FOREIGN KEY([DivisionCode])
REFERENCES [dbo].[Divisions] ([SapCode])
GO
ALTER TABLE [dbo].[employee] CHECK CONSTRAINT [FK_employee_Divisions]
GO
/****** Object:  ForeignKey [FK_UserQuiz_employee]    Script Date: 01/15/2012 12:29:48 ******/
ALTER TABLE [dbo].[UserQuiz]  WITH CHECK ADD  CONSTRAINT [FK_UserQuiz_employee] FOREIGN KEY([Username])
REFERENCES [dbo].[employee] ([Username])
GO
ALTER TABLE [dbo].[UserQuiz] CHECK CONSTRAINT [FK_UserQuiz_employee]
GO
/****** Object:  ForeignKey [FK_UserQuiz_Quiz]    Script Date: 01/15/2012 12:29:48 ******/
ALTER TABLE [dbo].[UserQuiz]  WITH CHECK ADD  CONSTRAINT [FK_UserQuiz_Quiz] FOREIGN KEY([QuizID])
REFERENCES [dbo].[Quiz] ([QuizID])
GO
ALTER TABLE [dbo].[UserQuiz] CHECK CONSTRAINT [FK_UserQuiz_Quiz]
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:03:38+00:00Added an answer on May 28, 2026 at 4:03 am

    Try this one:

    SELECT 
        COUNT(DISTINCT dbo.employee.UserName) UserCount,
        (SELECT COUNT(*) FROM dbo.Quiz) AS [Total Number of Quizzes],  
        (SELECT COUNT(*) FROM dbo.Quiz)*COUNT(DISTINCT dbo.employee.UserName) AS [Total Number of Quizzes for All users],  
        dbo.Divisions.DivisionName,
        DATENAME(Month, dbo.UserQuiz.DateTimeComplete) AS MONTH,
        COUNT(DISTINCT dbo.UserQuiz.QuizId)*COUNT(DISTINCT dbo.employee.UserName) AS [Completed This Month],
        COUNT(DISTINCT dbo.UserQuiz.QuizId)*100/(SELECT COUNT(*) FROM dbo.Quiz) AS [Percent Completion]
    FROM dbo.employee
    JOIN  dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode
    LEFT JOIN dbo.UserQuiz ON dbo.UserQuiz.Username = dbo.employee.Username 
    WHERE dbo.UserQuiz.DateTimeComplete IS NOT NULL
    GROUP BY 
        dbo.Divisions.DivisionName, 
        DATENAME(Month, dbo.UserQuiz.DateTimeComplete)
    

    just the percent completion for each division in the last month only?

    SELECT 
        dbo.Divisions.DivisionName,
        DATENAME(Month, dbo.UserQuiz.DateTimeComplete) AS MONTH,
        COUNT(DISTINCT dbo.UserQuiz.QuizId)*COUNT(DISTINCT dbo.employee.UserName)*100/((SELECT COUNT(*) FROM dbo.Quiz)*COUNT(DISTINCT dbo.employee.UserName)) AS [Percent Completion]
    FROM dbo.employee
    JOIN  dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode
    LEFT JOIN dbo.UserQuiz ON dbo.UserQuiz.Username = dbo.employee.Username 
    WHERE 
        dbo.UserQuiz.DateTimeComplete IS NOT NULL
    AND DATEPART(MONTH, dbo.UserQuiz.DateTimeComplete) = 12
    GROUP BY 
        dbo.Divisions.DivisionName, 
        DATENAME(Month, dbo.UserQuiz.DateTimeComplete)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing web application where users have collection of tags. I need to
I am developing an ASP.NET intranet web application that provides short quizzes to the
I'm developing a web application and I need to mix Forms & Windows authentication
I am developing a web application using Spring JS and Dojo Toolkit. In this
I'm developing a new web-based financial application for our company that provides online real-time
My company is currently developing a project management web application in PHP, and I
I'm currently developing a web application using MYSQL database InnoDB format and need some
I am developing an intranet web application which should provide its users with a
Recently we were developing web application based on Vaadin and Spring (Core). Now we
I'm developing a web application for a company which I work for. My team

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.