根据sql查询的数据分配点
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来像简单的算术(假设员工 456 的美元 = 5 是一个拼写错误,它应该是 500)
请注意 floor() 函数
换句话说,它总是向下舍入。您还可以使用 round() 函数,但表达式不会那么简单。
Seems like simple arithmetic (assuming the dollars = 5 for employee 456 is a typo and it should be 500)
note that the floor() function
In other words it always rounds down. You could also use the round() function, but the expression wouldn't be as straight-forward.