[英]How would I go about reducing the price of a service by 10% in SQL using an update statement?
This is the table with the relevant values. 这是具有相关值的表。
More specifically I need a 5% reduction on both Job_man_hours and Labour_Cost_Per_Hour to equal out to 10%. 更具体地说,我需要Job_man_hours和Labour_Cost_Per_Hour都减少5%,以等于10%。 Just not sure how to do this and havent found much online.
只是不确定如何做到这一点,还没有在网上找到很多东西。
INSERT INTO Work_Summary
(
Invoice_No,Invoice_Date,Order_Quantity,Job_man_hours,Job_Desc
,Labour_Cost_Per_Hour,Job_Number,Product_Code
)
VALUES
(1,'2017/05/18',2,'1:20:00','Description',100.00,1,'PC_1001'),
(2,'2017/05/18',6,'2:30:00','Description',75.00,2,'PC_1002'),
(3,'2017/05/18',7,'3:10:00','Description',50.00,3,'PC_1003'),
(4,'2017/05/18',1,'4:35:00','Description',20.00,4,'PC_1004'),
(5,'2017/05/18',9,'5:50:00','Description',15.00,5,'PC_1005'),
(6,'2017/05/18',11,'6:30:00','Description',10.00,6,'PC_1006'),
(7,'2017/05/18',1,'2:00:10','Description',18.95,7,'PC_1007'),
(8,'2017/05/18',6,'2:30:50','Description',19.99,8,'PC_1008'),
(9,'2017/05/18',8,'3:00:25','Description',40.00,9,'PC_1009'),
(10,'2017/05/18',9,'1:30:18','Description',30.00,10,'PC_1010'),
(11,'2017/05/18',14,'2:00:10','Description',20.95,11,'PC_1011'),
(12,'2017/05/18',3,'2:30:11','Description',9.99,12,'PC_1012'),
(13,'2017/05/18',6,'3:00:45','Desription',199.99,13,'PC_1013'),
(14,'2017/05/18',8,'3:30:34','Description',200.00,14,'PC_1014'),
(15,'2017/05/18',9,'4:00:54','Description',500.00,15,'PC_1015')
To reduce all values in both columns by 5% each (which seems to be your requirement - if it's not, please be more specific about your expected results), you can use these statements: 要将两列中的所有值均减少5%(这似乎是您的要求-如果不是,请更详细地说明您的预期结果),可以使用以下语句:
UPDATE Work_Summary SET job_man_hours = (job_man_hours*0.95);
UPDATE Work_Summary SET labour_cost_per_hour = (labour_cost_per_hour *0.95);
EDIT: I just realized that I looked at the wrong argument in your INSERT-statment for the value of job_man_hours. 编辑:我只是意识到我在INSERT语句中为job_man_hours的值看了错误的参数。 Applying the update above to a value like
01:20:00
will not work. 将上面的更新应用于
01:20:00
类的值将不起作用。
In order to find a solution for casting your value to something we can calculate on, we'd need to know which datatype you are using for the job_man_hours column. 为了找到将您的价值转化为我们可以计算的结果的解决方案,我们需要知道job_man_hours列使用的是哪种数据类型。
If your job_man_hours
is a time
data type you can get the total seconds, multiple that by 0.95
, and convert it back to time
using dateadd()
and convert()
: 如果
job_man_hours
是time
数据类型,则可以获取总秒数,将其乘以0.95
,然后使用dateadd()
和convert()
将其转换回time
:
update work_summary
set Labour_Cost_per_hour = (Labour_Cost_per_hour*0.95)
, Job_man_hours = (convert(time,dateadd(second,datediff(second,0,job_man_hours)*0.95,0)))
rextester demo: http://rextester.com/EQRD5100 extrester演示: http ://rextester.com/EQRD5100
returns: 返回:
+------------+--------------+----------------+---------------+-------------+----------------------+------------+--------------+
| Invoice_No | Invoice_Date | Order_Quantity | Job_man_hours | Job_Desc | Labour_Cost_Per_Hour | Job_Number | Product_Code |
+------------+--------------+----------------+---------------+-------------+----------------------+------------+--------------+
| 1 | 2017-05-18 | 2 | 01:16:00 | Description | 95,0000 | 1 | PC_1001 |
| 2 | 2017-05-18 | 6 | 02:22:30 | Description | 71,2500 | 2 | PC_1002 |
| 3 | 2017-05-18 | 7 | 03:00:30 | Description | 47,5000 | 3 | PC_1003 |
| 4 | 2017-05-18 | 1 | 04:21:15 | Description | 19,0000 | 4 | PC_1004 |
| 5 | 2017-05-18 | 9 | 05:32:30 | Description | 14,2500 | 5 | PC_1005 |
| 6 | 2017-05-18 | 11 | 06:10:30 | Description | 9,5000 | 6 | PC_1006 |
| 7 | 2017-05-18 | 1 | 01:54:09 | Description | 18,0025 | 7 | PC_1007 |
| 8 | 2017-05-18 | 6 | 02:23:17 | Description | 18,9905 | 8 | PC_1008 |
| 9 | 2017-05-18 | 8 | 02:51:23 | Description | 38,0000 | 9 | PC_1009 |
| 10 | 2017-05-18 | 9 | 01:25:47 | Description | 28,5000 | 10 | PC_1010 |
| 11 | 2017-05-18 | 14 | 01:54:09 | Description | 19,9025 | 11 | PC_1011 |
| 12 | 2017-05-18 | 3 | 02:22:40 | Description | 9,4905 | 12 | PC_1012 |
| 13 | 2017-05-18 | 6 | 02:51:42 | Desription | 189,9905 | 13 | PC_1013 |
| 14 | 2017-05-18 | 8 | 03:20:02 | Description | 190,0000 | 14 | PC_1014 |
| 15 | 2017-05-18 | 9 | 03:48:51 | Description | 475,0000 | 15 | PC_1015 |
+------------+--------------+----------------+---------------+-------------+----------------------+------------+--------------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.