在SQL语句中除法。 [英] Division in a SQL statement.

查看:1366
本文介绍了在SQL语句中除法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我的问题:

我有一个表itemconfig,其中有很多数据存储在我们的仓库中。我需要选择特殊的项目,以便进行一些与工作相关的测试。到目前为止,当我滚动数据库时,我脑子里一直在做数学运算,但是肯定有一种更简单的方法。

I have a table itemconfig where there is lots of data concerning items stored in our warehouses. I need to select a special group of items so I can do some job related testing. So far I've been doing the math in my head as I scroll through the database but there must be an easier way.

在itemconfig中,我想专门查看case_qty和pal_qty以及itm_num列。我想做的是选择所有itm_num,其中 pal_qty / case_qty 大于 500 。这将立即给我所有与测试相关的 itm_num 。遗憾的是,我不知道如何执行此操作,甚至可能不熟悉。

Within itemconfig I want to specifically look at columns case_qty and pal_qty and itm_num. What I would like to do is select all itm_num where pal_qty / case_qty is greater than say 500. This would give me all itm_num instantly that are relevant to my tests. Sadly I'm not familiar with how to do this or if it's even possible.

谢谢。

推荐答案

在大多数SQL方言中都实现了除法:使用 / ,例如

Division is implemented in most SQL dialects: use /, like this:

select * from table
where  pal_qty / case_qty > 500

假设 case_qty 为非负数,您可以通过将两边都乘以 case_qty pal_qty 上的索引,如果有*) >:

Assuming case_qty is non-negative, you can shield yourself from division by zero (and use indexes on pal_qty, if any*) by multiplying both sides by case_qty:

select * from table
where  pal_qty > 500 * case_qty






*谢谢文森特·萨瓦德对此观察。

这篇关于在SQL语句中除法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆