如何在Google表格中编写此查询

时间:2019-06-27 18:55:35

标签: google-sheets

select year || '-'|| periodo perido,  COUNT(DISTINCT codigo ) total,
SUM (CASE WHEN (desertor ='S' ) THEN 1 ELSE 0 END ) desertores,
  SUM (CASE WHEN (semfin=1  and desertor ='S' ) THEN 1 ELSE 0 END ) /   COUNT(DISTINCT codigo )   I,
  SUM (CASE WHEN (semfin=2 and desertor ='S' ) THEN 1 ELSE 0 END ) / COUNT(DISTINCT codigo )  II,
  SUM (CASE WHEN (semfin=3 and desertor ='S' ) THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  III,
  SUM (CASE WHEN (semfin=4  and desertor ='S') THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  IV,
  SUM (CASE WHEN (semfin=5 and desertor ='S' ) THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  V,
  SUM (CASE WHEN (semfin=6 and desertor ='S' ) THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  VI,
  SUM (CASE WHEN (semfin=7  and desertor ='S' ) THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  VII,
  SUM (CASE WHEN (semfin=8  and desertor ='S' ) THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  VIII,
  SUM (CASE WHEN (semfin=9 and desertor ='S' ) THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  IX,
  SUM (CASE WHEN (semfin=10  and desertor ='S') THEN 1 ELSE 0 END )/ COUNT(DISTINCT codigo )  X from ACOHORTE 
  group by year, periodo order by year , PERIODO;

0 个答案:

没有答案