Jump to content

ExecuteSQL Query


This topic is 3948 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

Hi I have been searching all over for an answer to this. Simply put I have a table (members) with fields (branches, gender) and a heap of others what I need is through a SQL query to get the following for a certain date. Here is a pic(capture1) of what I mean. I need a list of the branches with the male/female numbers and totals. I have managed half of it but cannot get the males/females to display together. I hope someone can help asap. Thanks so much, in the meantime I'll keep trying...Regards

 

post-109325-0-19183200-1374211381_thumb.

Link to comment
Share on other sites

We can't help you with a SQL query without knowing more about the relational structure of your solution. What fields do you have in what tables that this is drawing from? What have you tried so far, and what result did you get with that?

Link to comment
Share on other sites

  • Newbies

We can't help you with a SQL query without knowing more about the relational structure of your solution. What fields do you have in what tables that this is drawing from? What have you tried so far, and what result did you get with that?

So far, The fields are all from one table (members13). The data is being pulled from the fields memnum (membership number), Branch (name of the branch), Gender (male/female) and the current month from a variable input. I have tried using :-

SELECT Branch, COUNT(*)

FROM members13

GROUP BY Branch

which gives me a list of the branches and the total members for each branch.

have also tried:-

SELECT Branch, COUNT(*)

FROM members13

WHERE Gender = 'Male'

GROUP BY Branch

which gives me a list of the branches with all the male totals.

I need this in 1 query (if possible) or the easiest way to get the results below:

BRANCH - TOTAL MALES - TOTAL FEMALES - TOTAL

branch1               20                         18                  38

branch2               44                          21                 65

etc. 

Hope this helps

Link to comment
Share on other sites

You can do it in query, but not with one SELECT.  So for each gender you need to embed one SELECT...WHERE and one "master" SELECT around the whole thing to include the branch.  So your query will have three SELECTs in it.

Link to comment
Share on other sites

actually this should work:

 

 

"SELECT 
branch,
COUNT(*) AS totalCount,
SUM( case when gender = 'F' then 1 else 0 end) as females,
SUM( case when gender = 'M' then 1 else 0 end) as males 
FROM theData 
GROUP BY branch"
  • Like 1
Link to comment
Share on other sites

This topic is 3948 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.