简体   繁体   English

在每一行的列中将值加倍

[英]Double a value in a column on every row

I need to double the price of all items in a table of a database in access. 我需要将Access中数据库表中所有项目的价格加倍。 Here is what the table structure looks like: 表结构如下所示:

sandwich $5.12 三明治$ 5.12
apple $1.25 苹果$ 1.25

I need it to become: 我需要它成为:

sandwich $10.24 三明治$ 10.24
apple $2.50 苹果$ 2.50

How can I accomplish this? 我该怎么做?

使用UPDATE语句将price设置为2 * price。

In Access 2010, create and save a query by navigating to Create > Query Design > [Table Name] > Add > Close . 在Access 2010中,通过导航到“ 创建” >“ 查询设计” >“ [表名]” >“ 添加” >“ 关闭”创建和保存查询。 Right-click on the query heading and select SQL View to use these solutions. 右键单击查询标题,然后选择“ SQL视图”以使用这些解决方案。

To use jzd's method, you can use an update query to change the values in your table. 要使用jzd的方法,可以使用更新查询来更改表中的值。

UPDATE Rates SET Rates.Price = Rates.Price*2;

If you want to retain the original price in the table however, a select query might be a better option. 但是,如果要保留表中的原始价格,选择查询可能是一个更好的选择。

SELECT Rates.Item, Price*2 AS Doubled
FROM Rates;

In both of these solutions, replace " Rates " with your [Table Name] . 在这两种解决方案中,都用[Table Name]替换“ Rates ”。 " Item " is the product name field, " Price " is the product cost field, and " Doubled " is an example of how to attribute a new name to a calculated field. 项目 ”是产品名称字段,“ 价格 ”是产品成本字段,“ 加倍 ”是如何将新名称归因于计算字段的示例。 You can always switch back to the Design View to see how these selectors are used to easily build SQL queries. 您始终可以切换回“ 设计视图”,以查看如何使用这些选择器轻松构建SQL查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM