使用INSERT可以增加列中的现有值吗? [英] With INSERT can I increment an existing value in a column?

查看:54
本文介绍了使用INSERT可以增加列中的现有值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



伙计,


我有一张地址表和一个带有联系人姓名的单独表格 -

所有地址都有关系一个或多个名字 - 我想跟踪

一个地址的''属于''的名字,因此在我的地址中包含了一个

列表名为num_of_contacts。每次我添加一个

的新联系人,我想增加

地址表中的num_of_contacts列。


这是可能吗?


我认为没有(至少,到目前为止我的尝试都没有让我失望)所以如果有人能告诉我的话,我会赞赏它。如果我浪费我的时间尝试

而是选择记录,增加它,然后更新它。


欢呼

randell d。


Folks,

I have a table of addresses and a seperate table with contact names -
All addresses tie to one or more names - I would like to keep track of
the number of names ''belonging'' to an address and have thus included a
column in my address table called num_of_contacts. Everytime I add a
new contact, I would like to increment the num_of_contacts column in the
address table.

Is this possible?

Me thinks not (or at least, my attempts so far have failed me) so I''d
appreciate it if someone could tell me if I am wasteing my time trying
and instead SELECT the record, increment it, then UPDATE it.

cheers
randell d.

推荐答案

2005年2月16日星期三09:17:59 GMT,在mailing.database.mysql" Randell

D. < re ****************************** @ fiprojects.moc>写道:
On Wed, 16 Feb 2005 09:17:59 GMT, in mailing.database.mysql "Randell
D." <re******************************@fiprojects.moc > wrote:
|
|伙计们,
|
|我有一张地址表和一个带有联系人姓名的单独表格 -
|所有地址都与一个或多个名字相关 - 我想跟踪
| 地址的名称数量,因此包含了一个
|我的地址表中的列名为num_of_contacts。每次我加一个
|新的联系方式,我想增加
|中的num_of_contacts列地址表。
|
|这可能吗?
|
|我认为没有(至少,到目前为止我的尝试都没有让我失望)所以我会
|如果有人能告诉我我是否在浪费时间尝试
|,请欣赏它然后选择记录,增加它,然后更新它。
|
| Folks,
|
| I have a table of addresses and a seperate table with contact names -
| All addresses tie to one or more names - I would like to keep track of
| the number of names ''belonging'' to an address and have thus included a
| column in my address table called num_of_contacts. Everytime I add a
| new contact, I would like to increment the num_of_contacts column in the
| address table.
|
| Is this possible?
|
| Me thinks not (or at least, my attempts so far have failed me) so I''d
| appreciate it if someone could tell me if I am wasteing my time trying
| and instead SELECT the record, increment it, then UPDATE it.




将计算值存储到表中并不是一个好主意。使用

查询返回最新信息。


----------------- ----------------------------------------------
jn******@yourpantsyahoo.com.au :脱掉裤子回复

----------------------------------------------- ----------------



Its not a good idea storing calculated values into a table. Use
queries to return the most up-to-date information.

---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------




" Randell D." < re ****************************** @ fiprojects.moc>写在

消息新闻:bdEQd.405430

"Randell D." <re******************************@fiprojects.moc > wrote in
message news:bdEQd.405430


8l.184243@pd7tw1no ...
8l.184243@pd7tw1no...

人们,

我有一个地址表和一个带有联系人姓名的单独表格 -
所有地址都与一个或多个名字相关 - 我想跟踪
名称的数量' '属于'一个地址,因此在我的地址表中包含了一个名为num_of_contacts的列。每次我添加一个
新联系人时,我想增加
地址表中的num_of_contacts列。

这可能吗?


可能 - 是的。好主意 - 不!


您的数据库旨在为您计算这些名称(联系人)。你想要

来形成一个SELECT查询,它会产生你的[num_of_contacts]。完成

这样,在您询问

问题时,您的号码始终是正确的。作为一项规则,您永远不想存储一个可以从现有信息中动态计算

的数字。如果您需要帮助,请再提供一些

的详细信息,有人会帮助您设计一个正确的SELECT查询,这将为您提供所需的COUNT。

我认为没有(或者至少,到目前为止我的尝试都没有让我失望)所以如果有人能告诉我我是否在浪费时间尝试
而是选择记录,我会很感激,增加它,然后更新它。

Folks,

I have a table of addresses and a seperate table with contact names -
All addresses tie to one or more names - I would like to keep track of
the number of names ''belonging'' to an address and have thus included a
column in my address table called num_of_contacts. Everytime I add a
new contact, I would like to increment the num_of_contacts column in the
address table.

Is this possible?
Possible - yes. Good idea - no!

Your database is designed to count those names (contacts) for you. You want
to form a SELECT query that will yield up your [num_of_contacts]. Done in
this way your number will always be correct at the moment you ask the
question. As a rule, you never want to store a number that you can calculate
on the fly from existing information. If you need help, give a few more
details and someone will help you design a proper SELECT query that will
yield the COUNT you need.
Me thinks not (or at least, my attempts so far have failed me) so I''d
appreciate it if someone could tell me if I am wasteing my time trying
and instead SELECT the record, increment it, then UPDATE it.




你会浪费时间尝试从SELECT

语句中更新字段。你必须使用*单独的UPDATE

语句来增加它*

UPDATE地址

WHERE {RecId} = id

SET num_of_contacts = num_of_contacts + 1


假设你确实需要这样做!

Thomas Bartkus



You would be wasting your time trying to UPDATE a field from inside a SELECT
statement. You will have to increment it *using* a separate UPDATE
statement.
UPDATE addresses
WHERE {RecId} = id
SET num_of_contacts = num_of_contacts + 1

Assuming you really needed to do that!
Thomas Bartkus


这篇关于使用INSERT可以增加列中的现有值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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