将列数据汇总为描述性数据

时间:2019-01-16 18:46:46

标签: sql ms-access

我有一个看起来像这样的数据表。它基本上包含每个星期天到达的人的记录以及其他一些描述性变量。

Pt_ID  `Checkin_Date          ESI 1 or 2`     ESI 3    ESI4
  1     Sunday 07/Jan/2018        1           0        0
  2     Sunday 07/Jan/2018        1           0        0   
  3     Sunday 07/Jan/2018        0           1        0
  4     Sunday 14/Jan/2018        0           1        0
  5     Sunday 14/Jan/2018        0           1        0
  6     Sunday 14/Jan/2018        0           0        1
  7    Sunday 21/Jan/2018         1           0        0   
  8    Sunday 21/Jan/2018         1           0        0   

我想计算一个变量,该变量显示在给定星期日到达的人数和“ ESI 1或2”人数的百分比。

我希望输出看起来像这样...

  Checkin_Date        Count         ESI 1 or 2
Sunday 07/Jan/2018      3               66%
Sunday 14/Jan/2018      3                0%
Sunday 21/Jan/2018      2              100%

我有以下代码进行计数,但是在创建百分比方面很费力。

Select checkin_date, count (pt_Id) as [Number of Patients Seen]
from [Fast Track Quality Research v1]
group by checkin_date

1 个答案:

答案 0 :(得分:1)

由于您的load_model字段仅包含1和0,因此ESI 1 or 2应该会产生所需的结果,例如:

AVG

或者select checkin_date, count(pt_Id) as [Number of Patients Seen], avg([esi 1 or 2])*100 as pct from [Fast Track Quality Research v1] group by checkin_date ,例如:

SUM/COUNT