Использование GREATEST
SELECT Country, 'unconfirmed', GREATEST(Confirmed, Unconfirmed, Deaths, Recovered)
FROM TAble1;
Еще немного контента
Ваш полный запрос выглядит следующим образом
SELECT
t1.country
, ( case
WHEN t1.Confirmed = t2.maxnumber Then 'Confirmed'
WHEN t1.Unconfirmed = t2.maxnumber Then 'Unconfirmed'
WHEN t1.Deaths = t2.maxnumber Then 'Deaths'
WHEN t1.Recovered = t2.maxnumber Then 'Recovered'
ELSE 'unknown'
END) type
,t2.maxnumber
FROM table1 t1 inner join
(SELECT
Country
,GREATEST(Confirmed , Unconfirmed , Deaths , Recovered ) maxnumber
FROM table1) t2 ON t1.country = t2.country
Пример
Схема (MySQL v5.7)
CREATE TABLE table1 (
`Country` VARCHAR(1),
`Confirmed` INTEGER,
`Unconfirmed` INTEGER,
`Deaths` INTEGER,
`Recovered` INTEGER
);
INSERT INTO table1
(`Country`, `Confirmed`, `Unconfirmed`, `Deaths`, `Recovered`)
VALUES
('A', '95782', '1034219', '6723', '25892'),
('B', '95782', '1034219', '6723', '2225892');
Запрос # 1
SELECT
t1.country
, ( case
WHEN t1.Confirmed = GREATEST(Confirmed , Unconfirmed , Deaths , Recovered ) Then 'Confirmed'
WHEN t1.Unconfirmed = GREATEST(Confirmed , Unconfirmed , Deaths , Recovered ) Then 'Unconfirmed'
WHEN t1.Deaths = GREATEST(Confirmed , Unconfirmed , Deaths , Recovered ) Then 'Deaths'
WHEN t1.Recovered = GREATEST(Confirmed , Unconfirmed , Deaths , Recovered ) Then 'Recovered'
ELSE 'unknown'
END) type
,GREATEST(Confirmed , Unconfirmed , Deaths , Recovered )
FROM table1 t1;
| country | type | GREATEST(Confirmed , Unconfirmed , Deaths , Recovered ) |
| ------- | ----------- | -------------------------------------------------------- |
| A | Unconfirmed | 1034219 |
| B | Recovered | 2225892 |
Посмотреть на БД Fiddle