【发布时间】:2020-11-04 18:51:53
【问题描述】:
我希望通过在医疗保健计算器上使用预定义权重来计算空变量,并且我希望输出是变量权重与总可用权重的总和。正如您在下面看到的,希望是“sum/8”。
CREATE TABLE `trial`.`trial` ( `Name` TEXT NULL , `Age` INT NULL , `BP systolic` INT NULL , `BP diastolic` INT NULL ,`Clinical features of the TIA` TEXT NULL , `Duration of symptoms` INT NULL , `History of diabetes` TEXT NULL , `ABCD² Score for TIA` FLOAT NULL ) ENGINE = InnoDB;
INSERT INTO `trial` (`Name`, `Age`, `BP systolic`, `BP diastolic`, `Clinical features of the TIA`, `Duration of symptoms`, `History of diabetes`, `ABCD² Score for TIA`) VALUES ('Person A', '71', '137', '85', 'Speech disturbance without weakness', '17', 'Yes', NULL);
INSERT INTO `trial` (`Name`, `Age`, `BP systolic`, `BP diastolic`, `Clinical features of the TIA`, `Duration of symptoms`, `History of diabetes`, `ABCD² Score for TIA`) VALUES ('Person B', '92', '125', '78', 'Other symptoms', '43', 'Yes', NULL);
INSERT INTO `trial` (`Name`, `Age`, `BP systolic`, `BP diastolic`, `Clinical features of the TIA`, `Duration of symptoms`, `History of diabetes`, `ABCD² Score for TIA`) VALUES ('Person C', '27', '130', '90', 'Other symptoms', '34', 'No', NULL);
update trial
set ABCD² Score for TIA = case when (
case when Age = >=60 then 1 else 0 end
+ case when BP systolic = >= 140 then 1 else 0 end
+ case when BP diastolic = >=90 then 1 else 0 end
+ case when Clinical features of the TIA = 'Unilateral weakness' then 2 end
+ case when Clinical features of the TIA = 'Speech disturbance without weakness' then 1 end
+ case when Clinical features of the TIA = 'Other symptoms' then 0 end
+ case when Duration of symptoms = <10 then 0 end
+ case when Duration of symptoms = 10-59 then 1 end
+ case when Duration of symptoms = >= 60 then 2 end
+ case when History of diabetes = 'Yes' then 1 else 0 end
) sum/8
where ABCD² Score for TIA is null
【问题讨论】:
-
你不能写
= >=60。它应该只是>= 60。 -
为什么有嵌套的 case 表达式?
-
在列名中有空格会使事情变得更加复杂。在这里,您需要在查询中引用所有这些标识符。
标签: mysql sql phpmyadmin