Home > database >  How to calculate the number of men and women
How to calculate the number of men and women

Time:11-26

I have 2 form
Table: service
ServiceID clientID service
1 1 Call
2 1 Email
3 2 Call
4 3 Email
5 1 Email

Table: Client
ClientID Gendar birthday City
1 M..
2 M..
3 F
4 F
5 M

I need to calculate the number of email service men and women (can't repeat, such as clientID 1 we email 2 times, but he is with 1 person, so the number of male only + 1

Thank you for the

CodePudding user response:

The service table inside distint clientID, then group by the client ID, use count (*) to calculate the quantity, and then join the client form, then group by gender

CodePudding user response:

Select count (distinct clintID) from (
The select a.c lientID, a.s ervice, b.G endar from service a left join Client b on a.c lientID=biggest lientID) c where service='Email' and Gendar='F'

CodePudding user response:

 SELECT 
B.G endar
, and COUNT (DISTINCT A.c lientID) AS CT
FROM the service AS A
JOIN the Client AS B ON A.c lientID=biggest lientID
WHERE A.s ervice='email'
GROUP BY

CT is the desires of your email service, the number of men and women

CodePudding user response:

 SELECT 
B.G endar
, and COUNT (DISTINCT A.c lientID) AS CT
FROM the service AS A
JOIN the Client AS B ON A.c lientID=biggest lientID
WHERE A.s ervice='email'
GROUP BY
B.G endar

CT is the desires of your email service in the number of men and women
  • Related