
select case when 除数 =0 then 0 else 被除数/除数 end
一. 基本概念
SQL语言,是结构化查询语言(Structured Query Language)的简称。SQL语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;同时也是数据库脚本文件的扩展名。
二. 支持标准
SQL 是1986年10 月由美国国家标准局(ANSI)通过的数据库语言美国标准,接着,国际标准化组织(ISO)颁布了SQL正式国际标准。1989年4月,ISO提出了具有完整性特征的SQL89标准,1992年11月又公布了SQL92标准,在此标准中,把数据库分为三个级别:基本集、标准集和完全集。
三. 记录筛选
sql="select * from 数据表 where字段名=字段值 order by字段名[desc]"(按某个字段值降序排列。默认升序ASC)
sql="select * from 数据表 where字段名like '%字段值%' order by 字段名 [desc]"
sql="select top 10 * from 数据表 where字段名=字段值 order by 字段名 [desc]"
sql="select top 10 * from 数据表 order by 字段名 [desc]"
sql="select * from 数据表 where字段名in ('值1','值2','值3')"
sql="select * from 数据表 where字段名between 值1 and 值2"
这样:
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
)
)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)