第三列没有在我的代码上执行

  • 本文关键字:代码 执行 三列 sql
  • 更新时间 :
  • 英文 :


我在同一张表上通过计算比率t1/t2来计算t3中的百分比,不幸的是我没有结果。你能帮我修复这个代码吗?

提前感谢

select 
( --Echantillon en test
SELECT count(*) nombre_enreg
FROM prdiction_AVC1) as t1
( --Nombre total AVC(H/F)
select count(*)
from prdiction_AVC1
where stroke=1) as t2
Select 
--Echantillon en test
(( SELECT count(*) nombre_enreg
FROM prdiction_AVC1) Echantillon
/
( --Nombre total AVC(H/F)
select count(*)
from prdiction_AVC1
where stroke=1) Total_avc))*100 as t3
from t1,t2

from prdiction_AVC1;

APH基本上用他/她的第一条评论回答了这个问题,但这是你可以做的:

select 
count(*) as total, 
count(case when stroke = 1 then 1 end) as sub_total,
count(case when stroke = 1 then 1 end)*100.0/count(*) as sub_pct
from prdiction_AVC1

输出:

total  sub_total  sub_pct
3      1          33.333333

我用不同的方式表达自己。我想在同一张表上创建第三列。此列应通过执行(t2/t1(*100 来计算百分比

如果我停留在前两个请求,一切都很好,不幸的是,当我添加第三个请求时,我会收到一条阻塞消息,所以第三列不会显示。

选择--受试者人数(H/F((SELECT计数(*(FROM PREdiction_AVC1(作为t1,

--Nombre total AVC(H/F)
(select count(*)
from prdiction_AVC1
where stroke=1) as t2,

select t2/t1*100 as t3
from t1,t2       

来自prdiction_AVC1;

我找到了自己的解决方案感谢所有

SELECT DISTINCT

--受试者人数(H/F((SELECT count(*(nombre_enregFROM prdiction_AVC1(作为Echantilon,

(--Nombre total AVC(H/F)
select count(*) total_AVC
from prdiction_AVC1
where stroke=1) as Nombre_avc,
(wITH
-- Forcer une colonne au real type de données
-- syntaxe SELECT CAST( expression AS type )
-- t1=echantillon, t2= nombre avc
t1 AS
(sELECT cast(COUNT(*) as real) nombre_enreg
FROM prdiction_AVC1)
,
--- 
t2 AS
(SELECT COUNT(*) total_AVC FROM prdiction_AVC1
where stroke=1)
SELECT round((t2.total_AVC/t1.nombre_enreg)*100,2) AS result FROM t1, t2) as pourcentage_avc

来自prdiction_AVC1;

最新更新