首页 > 解决方案 > 如何计算插入表单的数据数量

问题描述

我正在做一个项目,我需要确定插入数据库的学生是否患有冠状病毒,并且我的症状是复选框,如果选中则返回数字 1 如何使最后一列是状态计数1s 上的条目并返回状态是负的还是正的?

结果会是这样

[ID , Student , symptoms1 , symptom2 , symptom3 ,Status]
[1234 Scott   , 1.        , 1.       , 1.       , positive]

我试过了,但它仍然导致右括号出错

create table covid(ID NUMBER(7) , NAME VARCHAR2(32) ,DEPT VARCHAR2(16) , FEVER NUMBER(1) , 
COUGH NUMBER(1) ,TIREDNESS NUMBER(1) ,SHORT_BREATH NUMBER(1) ,SORE_THROAT NUMBER(1) ,
CHEST_PAIN NUMBER(1) ,LOSE_SENSES NUMBER(1),RUNNY_NOSE NUMBER(1), TEST_DATE DATE ,
SYMPTOMS NUMBER(16) ,
CASE
WHEN SYMPTOMS>= 3 THEN 'POSITIVE' ELSE 'NEGATIVE'
END AS RESULT);

标签: sqloracle

解决方案


一种方法,但是由于您没有说明如何根据症状的不同组合来评估状态,因此您需要按照逻辑要求放置

select id , student ,
case when symptoms1 = 1 and symptom2 = 1 and symptom3 =1 then 'POSITIVE' 
     when symptoms1 = 1 and symptom2 = 1 and symptom3 =0 then 'XXXXXXXX'
     when symptoms1 = 1 and symptom2 = 0 and symptom3 =1 then 'XXXXXXXX'
     when symptoms1 = 1 and symptom2 = 0 and symptom3 =0 then 'XXXXXXXX'
     when symptoms1 = 0 and symptom2 = 1 and symptom3 =1 then 'XXXXXXXX'
     when symptoms1 = 0 and symptom2 = 0 and symptom3 =1 then 'XXXXXXXX'
     when symptoms1 = 0 and symptom2 = 1 and symptom3 =0 then 'XXXXXXXX'
     when symptoms1 = 0 and symptom2 = 0 and symptom3 =0 then 'NEGATIVE'
 end as status
 from table 

推荐阅读