根据sql查询的数据分配点

发布于 2025-01-17 10:10:54 字数 623 浏览 5 评论 0原文

SQL(DB2)中是否有一种方法可以根据列值分配点,即每5个销售量,您就会得到一个点,每100美元就可以得到一个分?

我的查询:

SELECT SALES, DOLLARS, EMPLOYEE FROM EMP_SALES;

我想添加一个“积分”列,其中值是上面的销售/美元列中点的组合。因此,如果用户的销售量达到100美元以上,则将有2分。

在SQL中有一个好方法吗?还是我应该通过PHP执行此操作?

在此表中:

EMPLOYEE  |  SALES  |  DOLLARS
-------------------------------
123          5            100
456          5            500

我希望这些结果:

EMPLOYEE  |  SALES  |  DOLLARS  |  POINTS
-------------------------------------------
123          5            100        2   
456          5            5          6

Is there a way within sql (db2) to assign points based on values of columns, i.e. for every 5 sales you get one point and for every 100 dollars you get one point?

My query:

SELECT SALES, DOLLARS, EMPLOYEE FROM EMP_SALES;

I'd like to add a 'POINTS' column where the value is a combination of points from the sales/dollars columns like above. So if the user made 5 sales totaling over 100 dollars, they would have 2 points.

Is there a good way to do this in sql or should I just do this via PHP?

With this table:

EMPLOYEE  |  SALES  |  DOLLARS
-------------------------------
123          5            100
456          5            500

I would desire these results:

EMPLOYEE  |  SALES  |  DOLLARS  |  POINTS
-------------------------------------------
123          5            100        2   
456          5            5          6

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在看孤独的风景 2025-01-24 10:10:54

看起来像简单的算术(假设员工 456 的美元 = 5 是一个拼写错误,它应该是 500)

SELECT EMPLOYEE, SALES, DOLLARS
       , (sales/5) + floor(dollars/100) as points 
FROM EMP_SALES

请注意 floor() 函数

返回小于或等于表达式的最大整数值。

换句话说,它总是向下舍入。您还可以使用 round() 函数,但表达式不会那么简单。

Seems like simple arithmetic (assuming the dollars = 5 for employee 456 is a typo and it should be 500)

SELECT EMPLOYEE, SALES, DOLLARS
       , (sales/5) + floor(dollars/100) as points 
FROM EMP_SALES

note that the floor() function

returns the largest integer value less than or equal to expression.

In other words it always rounds down. You could also use the round() function, but the expression wouldn't be as straight-forward.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文