Answer the question
In order to leave comments, you need to log in
How to make such a SELECT from the values of one column multiplied by the value of another?
There are qveri
SELECT ps_ur AS UR, COUNT(ps_ur) AS Value FROM patient_services GROUP BY UR
UNION ALL
SELECT eng_ur AS UR, COUNT(eng_ur) AS Value FROM engagements WHERE LENGTH( eng_ur )>0 GROUP BY UR
UR Value
002035 3
002400 2
005441 4
SELECT
SUM( CASE WHEN patient_gender = 'Male' THEN 1 ELSE 0 END ) Male,
SUM( CASE WHEN patient_gender = 'Female' THEN 1 ELSE 0 END ) Female
FROM patients WHERE patient_ur
//Дальше не знаю что применить IN call foreach...
//Нужно из результатов первого запроса подсчитать пол и умножить на value
Answer the question
In order to leave comments, you need to log in
SELECT
SUM( CASE WHEN patient_gender = 'Male' THEN 1*xxx.Value ELSE 0 END ) Male,
SUM( CASE WHEN patient_gender = 'Female' THEN 1*xxx.Value ELSE 0 END ) Female
FROM patients JOIN (
SELECT ps_ur AS UR, COUNT(ps_ur) AS Value
FROM patient_services
GROUP BY UR
UNION ALL
SELECT eng_ur AS UR, COUNT(eng_ur) AS Value
FROM engagements
WHERE LENGTH( eng_ur )>0
GROUP BY UR ) xxx ON patients.patient_ur = xxx.UR
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question