如何更新表与其他数据仍在计算? [英] How to update Table with other data is still calculating?

查看:55
本文介绍了如何更新表与其他数据仍在计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我无法解释我的问题,但这里有解释:



我有一张桌子:

 ID ||产品|| TotalPrice || Price1 || DifPrice1 || Price2 || DifPrice2 || Price3 || DifPrice3 || 
01 ||铅笔|| 100.00 || 10.00 || .00 || 25.00 || .00 || 30.00 || .00 ||



I我希望用这个公式更新DifPrice,假设DifPrice有DifPrice10及以后:

TotalPrice - Price1 = DifPrice1

DifPrice1 - Price2 = DifPrice2

DifPrice2 - Price3 = DifPrice3

等等



DifPrice和TotalPrice是varchar。所以在查询的顶部可能会有一些转换。



感谢您的帮助!

解决方案

< blockquote>哦不,你应该开始学习正确的数据库设计 [ ^ ]。

这些是我的一些观察和建议:

首先,为什么varchar中的数据类型是什么?
其次,为什么需要存储价格差异,因为它们可以从总价格和各自的价格。想一想你存储在数据库中的出生日期和年龄?

最后,你不能继续添加新的列数量与priceN的数量一样多,而是将其更改为2个表格:

表:产品

product_id(主键)

product_name

表:product_price

product_id

product_price(product_id和product_price是复合键)

两个表都通过product_id以一对多的关系链接。


Hi!

I can't quite explain my question but here is the explanation:

I have a table:

ID||Products||TotalPrice||Price1||DifPrice1||Price2||DifPrice2||Price3||DifPrice3||
01||Pencil  ||100.00    ||10.00 ||.00      ||25.00 ||.00      ||30.00 ||.00      ||


I want to update the DifPrice with this formula supposing that DifPrice has DifPrice10 and onwards:
TotalPrice - Price1 = DifPrice1
DifPrice1 - Price2 = DifPrice2
DifPrice2 - Price3 = DifPrice3
and etc.

DifPrice and TotalPrice is varchar. So there might be some convertion in the top part of the query.

Thanks for the help!

解决方案

Oh no, you ought to start learning the correct way of database design[^].
These are some of my observations and suggestions:
First of all, why is data type of price in varchar?
Secondly, why do you need to store price difference as they are derivable from totalprice and the respective prices. Think about date of birth and age, which do you store in the database?
Lastly, you cannot keep adding new columns as many as the number of priceN, instead, change it into 2 tables:
table: product
product_id (primary key)
product_name
table: product_price
product_id
product_price (product_id and product_price are composite key)
both tables are linked through product_id in one to many relationship.


这篇关于如何更新表与其他数据仍在计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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