sql - 如何计算插入表单的数据数量
问题描述
我正在做一个项目,我需要确定插入数据库的学生是否患有冠状病毒,并且我的症状是复选框,如果选中则返回数字 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);
解决方案
一种方法,但是由于您没有说明如何根据症状的不同组合来评估状态,因此您需要按照逻辑要求放置
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
推荐阅读
- javascript - Css 和 JS 中的旋转
- php - 使用 Yii2 框架的 Ajax 请求太慢
- spring-boot - Spring Boot Metrics 与 Prometheus 和 grafana 设置更改为千分尺
- kdb - 从 2d 列表创建文件路径 kdb q
- c - Arduino 与普通 C 编译器的不同输出
- java - LibGDX - 是否可以指定全屏分辨率?
- c# - 单例、异步、ReaderWriterLock
- c++ - 统一初始化语法的使用
- javascript - ", expected" in opening and closing brackets, ESLint and JavaScript
- python - python请求带有标头和参数的POST