sql server - What's the best practise to write SQL to get data as follow? -


I have SQL Server 2005. The following two tables in DB 2 "User Infomeshn" ---> (ID ( Auto), name, gender (bit)) 1 "competitor" ---> (ID (auto), Ugraidi (user Instameshn. ID FK), status (Tinint)
I wanted to store my process That data comes back - Status - Male calculation - Female calculation - & nbsp; & nbsp; & nbsp; & nbsp; 1 & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; 45 & nbsp; nbsp; & nbsp; & nbsp; & nbsp; & Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; 15 < Br> & nbsp; & nbsp; nbsp; & nbsp; nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; 10 & nbsp; & nbsp; & nbsp; 10 & nbsp; 10 & nbsp; nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & Nbsp; & nbsp; & nbsp; & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 50
& nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 3 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 20 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp;

p>, COUNT (Competitors.ID) as MaleCount, (select count (C.ID) C, where the competitors as UserInfomration as UI UI.UserID = C.UserID and 0 UI.UserGender = and C .Status = Competitors.Status) as FemaleCount, (MaleCount + FemaleCount) Total UserInfomration be Competitors.Status competitors, UserInfomration.UserGender Left UserInfomration.UserID = ISEFCompetitors.UserID Group as external (UserInfomration.UserGender = 1 ) By joining Competitors.Status

Thank you in advance for your expected cooperation

You can try something like this

  SELECT c .Status, sUM (case when Ukjender = 0 then 1 ELSE 0 eND) guy, --assuming 0 M is the sum (case when UkGender = 1 then 1 and 0 at the end) I --assuming 1 competitors within c The woman is joined by UserInfomration u on c.UserID = u.ID c.Status  

Comments

Popular posts from this blog

MVP, design question -

excel - Populate list via a bi-Condition -

iphone - How do I make a UIPickerView in a UIActionSheet -