Allen :
My question is about How to pick up the Max Value from Crude_Rate
There are many same State and Year, As a part of the picture.
This is my code
SELECT M.Year, M.State, M.Disease, MAX(M.Crude_Rate)
FROM `MultipleDiseases` M
WHERE M.Year = 2000
AND NOT EXISTS(SELECT S.Disease From MultipleDiseases S WHERE S.Disease = "Total" AND S.Disease = M.Disease)
GROUP BY M.State
I want to find the max value of crude_rate and it is related to Disease columns. For example,
there is my outcome from the above coding
However, Disease column and Crude_Rate column can not match correctly.
Thank you.
Yogesh Sharma :
You can use correlated sub-query :
SELECT M.*
FROM `MultipleDiseases` M
WHERE M.Year = 2000
M.Crude_Rate = (SELECT MAX(M1.Crude_Rate)
FROM `MultipleDiseases` M1
WHERE M1.State = M.State AND M1.Disease <> "Total"
);