Unix Technical Forum

sum with update

This is a discussion on sum with update within the MySQL General forum forums, part of the MySQL category; --> Hi Everyone I have a question regarding SUM and Update. is it possible to use SUM with Update ? ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:48 AM
Ahmad Al-Twaijiry
 
Posts: n/a
Default sum with update

Hi Everyone

I have a question regarding SUM and Update.

is it possible to use SUM with Update ?

for example I have 3 tables

table_1:
idT1 Price
1 20
2 30
3 50
4 20

table_2:
idCust Total idT1
2 3011 2
2 221 1
4 2 2
3 31 1
2 302 4
2 30 1

table_3:
idCust Account
2 200
3 19
3 99


I want to update table_3.Account **IF** (table_3.Account +
SUM(table_2.Total* table_1.Price) ) small than 1000 for each customer
(idCust)

is this possible using only SQL or I have to do it in programming ?


Thanks
--
echo "Hello World "

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:49 AM
ViSolve DB Team
 
Posts: n/a
Default Re: sum with update

Hi,

Yes it is possible to use sum with Update, subject to the constraint -table
to be updated must not present in the FROM clause of the select stmt. But in
your query, the table to be updated is present in the FROM clause. Hence
update doesn't support that and have to go for some procedures..

Thanks
ViSolve DB Team

----- Original Message -----
From: "Ahmad Al-Twaijiry" <ahmadt@gmail.com>
To: "MySQL List" <mysql@lists.mysql.com>
Sent: Saturday, February 17, 2007 11:00 PM
Subject: sum with update


> Hi Everyone
>
> I have a question regarding SUM and Update.
>
> is it possible to use SUM with Update ?
>
> for example I have 3 tables
>
> table_1:
> idT1 Price
> 1 20
> 2 30
> 3 50
> 4 20
>
> table_2:
> idCust Total idT1
> 2 3011 2
> 2 221 1
> 4 2 2
> 3 31 1
> 2 302 4
> 2 30 1
>
> table_3:
> idCust Account
> 2 200
> 3 19
> 3 99
>
>
> I want to update table_3.Account **IF** (table_3.Account +
> SUM(table_2.Total* table_1.Price) ) small than 1000 for each customer
> (idCust)
>
> is this possible using only SQL or I have to do it in programming ?
>
>
> Thanks
> --
> echo "Hello World "
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:24 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com