We help IT Professionals succeed at work.
Get Started

Some TSQL

soozh
soozh asked
on
245 Views
Last Modified: 2021-04-21
SQL Server 2008!

I have a table that contains the following columns and data:

Date               Gender        Value
2010-01-15   M                   0
2010-01-15   M                  10
2010-01-15   M                  12
2010-01-15   F                  0
2010-01-15   F                  8
2010-01-15   F                  0
2010-02-15   M                  6
2010-02-15   M                  9
2010-02-15   M                  6
2010-02-15   F                  0
2010-02-15   F                  6
2010-03-15   M                  0

The table has a date column, a column for the patients gender, and a measurement.

I need a query that returns the following for each date
a) the % of patients that have a measurement greater than zero
b) the % of male patients that have a measurement greater than zero
c) the % of female patients that have a measurement greater than zero

So for the above data i think i should get

2010-01-15   50%   67%   33%
2010-02-15   80%   100%  50%
2010-03-15   0%      0%       0%

/thanks
Comment
Watch Question
Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This problem has been solved!
Unlock 2 Answers and 17 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE