SQL如何做除法

2025-04-09 10:15:39
推荐回答(1个)
回答1:

这样:

select

t.[origin-destination],t.[SH/LANE/MOT] /(select count(1) from ['TMS$'] ) AS PERCENTAGE
FROM (代码1) t

group by [origin-destination],t.[SH/LANE/MOT]

having t.[SH/LANE/MOT] /count(*) <= 0.01

注:两个count都是int,相除会没有小数部分,所以应该都给转成带小数的数。

cast as numeric(10,4) 。

扩展资料:

SQL中除法运算的实现

R(X,Y)÷S(Y,Z)的运算用结构化语言SQL 语句可表达为下列形式:

select distinct R.X from R R1

where not exists

select S.Y from S

where not exists

select * from R R2

where R2.X=R1.X and R2.Y=S.Y 

)