I have one table named PEOPLE (Sex, Age, Weight) listed here:
Sex Age Weight
M 10 81
F 21 146
M 32 179
F 40 129
F 58 133
I would like to have the following data returned (Sex, Age, Weight, Count(*) as SexCount from PEOPLE where Age < 35):
Sex Age Weight SexCount
M 10 81 2
F 21 146 3
M 32 179 2
I have found answers that work if I want to return all the people in the table (count without group).
But I have not found an answer if I want SexCount to include the total count from the whole table...and not just the total count from my returned subset. In other words, I want my returned data to just include people who are less than 35 years old, but I want the SexCount to include the count for all people in the table regardless of age.
Anyone know a query that will return the data I want from the table example above? I am using Oracle if it makes a difference.
I tried using this SQL phrase in my query:
COUNT(*) OVER(PARTITION BY Sex) as SexCount
But it only counted the number that were in my query results, and not in the whole table as I require (and explained above). Thanks.