首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用其他组件计算空变量的SQL数据库

使用其他组件计算空变量的SQL数据库
EN

Stack Overflow用户
提问于 2020-11-04 18:51:53
回答 2查看 30关注 0票数 1

我希望通过在医疗计算器上使用预先定义的权重来计算空变量,并且我希望输出是变量权重与总可用权重之和。正如你在下面看到的,希望这是"sum/8“。

代码语言:javascript
运行
复制
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
EN

Stack Overflow用户

回答已采纳

发布于 2020-11-04 19:06:16

必须修复案例表达式,并使用MySql的特性将布尔表达式计算为1或0:

代码语言:javascript
运行
复制
update trial 
set `ABCD² Score for TIA` = ( 
  (Age >= 60) + (`BP systolic` >= 140) + (`BP diastolic` >= 90) +
  case `Clinical features of the TIA`
    when 'Unilateral weakness' then 2 
    when 'Speech disturbance without weakness' then 1 
    when 'Other symptoms' then 0 
  end +  
  case
    when `Duration of symptoms` >= 60 then 2
    when `Duration of symptoms` >= 10 then 1
    when `Duration of symptoms` < 10 then 0
  end + 
  (`History of diabetes` = 'Yes')
) / 8 
where `ABCD² Score for TIA` is null

演示

结果:

代码语言:javascript
运行
复制
> Name     | Age | BP systolic | BP diastolic | Clinical features of the TIA        | Duration of symptoms | History of diabetes | ABCD² Score for TIA
> :------- | --: | ----------: | -----------: | :---------------------------------- | -------------------: | :------------------ | -------------------:
> Person A |  71 |         137 |           85 | Speech disturbance without weakness |                   17 | Yes                 |                  0.5
> Person B |  92 |         125 |           78 | Other symptoms                      |                   43 | Yes                 |                0.375
> Person C |  27 |         130 |           90 | Other symptoms                      |                   34 | No                  |                 0.25
票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64686047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档