• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Basic SQL query help

KAMAZON

Golden Member
So I've been trying to learn SQL and my associate came up with a interesting question. He wants the total number of instances where Mr, Mrs, Dr, etc. is used in the Northwind DB in MS-SQL. The info is in the dbo.Employees table under the TitleOfCourtesy row. I think I need to do a nested SQL SELECT statement but I'm not sure how to go at it. My failed attempt was this one:

USE Northwind
GO
SELECT COUNT (TitleOfCourtesy)
WHERE TitleOfCourtesy = 'Mr.'
FROM Employees
GO



Any suggestions? Thanks.
 
Your query will give you the count of people with Mr.
to get the count of each title and the title:

SELECT COUNT (TitleOfCourtesy), TitleOfCourtesy
FROM Employees
Group BY TitleOfCourtesy
 
TYVM for showing me groupby! I will have to review the different scenarios I can use that. My mistake in thinking through this was for the 2nd part, I wanted to see only the results that are greater than 1. Would anyone be able to tell me how I could do that part? Thanks again.
 
Originally posted by: KAMAZON
TYVM for showing me groupby! I will have to review the different scenarios I can use that. My mistake in thinking through this was for the 2nd part, I wanted to see only the results that are greater than 1. Would anyone be able to tell me how I could do that part? Thanks again.

SELECT COUNT (TitleOfCourtesy), TitleOfCourtesy
FROM Employees
Group BY TitleOfCourtesy
HAVING COUNT(TitleOfCourtesy) > 1
 
Originally posted by: KB
Your query will give you the count of people with Mr.
to get the count of each title and the title:

SELECT COUNT (TitleOfCourtesy), TitleOfCourtesy
FROM Employees
Group BY TitleOfCourtesy

Winnar... 🙂
 
Back
Top