If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Alter many cols in table with 1 command (and some maths)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-04, 08:45
damalo damalo is offline
Registered User
 
Join Date: Apr 2004
Posts: 12
Exclamation Alter many cols in table with 1 command (and some maths)

Hi all,

so i currently have a table with products in it. Each product contains 12 units. The prices i have in my db include some tax at 21%. As a special offer i want to sell a product item(12 units) at the price of 11 units.

So is there some way i can query the db and tell it to calculate the price of 1 unit and then 11 and then VAT for that 11 and update all prices.

I would do it on a checkout page but the catalog is db driven so i would like prices to be changed there also.

Any ideas guys?

Cheers,
damalo
Reply With Quote
  #2 (permalink)  
Old 06-03-04, 08:55
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Can you give us an example showing what you've got now, and what you want to get out of it?

-PatP
Reply With Quote
  #3 (permalink)  
Old 06-03-04, 08:59
damalo damalo is offline
Registered User
 
Join Date: Apr 2004
Posts: 12
sure,

so like so....

ID Product price
------- -------- -------
1 product1 $120

The above price is for 12 units with 21% tax included. I want to store a price for 11 of these units. So to get this...

120 / 12 = 10 (10$ for 1 unit and 21% tax)

11 units = $10 x 11 = $110

this new price is then sotred in the db.

Thanks again!
damalo
Reply With Quote
  #4 (permalink)  
Old 06-03-04, 09:03
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
That is a lot simpler than what I thought you meant. I'd just multiply by 11.0 / 12 and be done with it.

-PatP
Reply With Quote
  #5 (permalink)  
Old 06-03-04, 09:08
damalo damalo is offline
Registered User
 
Join Date: Apr 2004
Posts: 12
Red face

came up with this...


update products set price =( (price / 12) * 11 ) where id = 1;


looks like its the business!

Cheers!
(i think i confused myself there a bit aswell hehe)

damalo
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On