0
select count(*) from ("query1")
select count(*) from ("query2")
我想分兩個並獲得浮點結果。
我被告知要使用這樣的
SELECT (COUNT(smtg) * 1.0)/COUNT(smtg)
但林不知道
select count(*) from ("query1")
select count(*) from ("query2")
我想分兩個並獲得浮點結果。
我被告知要使用這樣的
SELECT (COUNT(smtg) * 1.0)/COUNT(smtg)
但林不知道
你可以這樣做:
select q1.cnt * 1.0/q2.cnt
from (select count(*) as cnt from ("query1")) q1 cross join
(select count(*) as cnt from ("query2")) q2;
或者,如果你喜歡:
select ((select count(*) from ("query1")) * 1.0/
(select count(*) from ("query2"))
)
from sysibm.sysdummy1;
其他解決方案(小心不要除以0)
with
query1 as (select count(*) as nb1 from ("query1")),
query2 as (select count(*) as nb2 from ("query2"))
select case when nb2=0 then null else nb1* 1.0/nb2 end as Result
from query1, query2