Update of MySQL Database with formula
Hallo,
Entschuldigung für mein Deutsch, aber ich hoffe es wird verständlich...
Ich bin neu hier und bei PHP/MySQL, und es würde mich freuen, eure Untestützung zu haben.
Ist es möglich, eine Spalte von einer Table mit einer Formel zu updaten?
Mein Beispiel: Table SALES.
Store......Product.......Units.........Price........Revenue Share %
A.............Apple..........10 ..........4.00
A.............Sony...........15...........4.20
B.............Apple..........22...........2.50
B.............Sony...........12...........2.80
C.............Apple..........44...........3.50
C.............Sony...........32...........3.80
"Revenue Share %" bedeutet der Sales-Beitrag jedes Produktes zu den Sales von jeden Store.
Die Formula: Revenue Share % = (PricexUnits) von der Linie / SUM(PricexUnits) von den Linien mit Store = Store von der Linie unter Berechnung, d.h. in der Linie 1, alle Linien mit Store = A.
Kann das auf Database Ebene gemacht werden, oder am bestens mit PHP Code?
Wenn beide möglich, welche ist besser von der Schnelligkeit her?
Welche wäre dann das PHP-Code?
BESTEN Dank im Voraus für die Hilfe!!!
FG,
ElBati
**UNTEN AUF ENGLISH; FALLS DIES NICHT VERSTAENDLICH IST**
-----------------------------------------
Hi there,
I am new here and also new to PHP/MySQL and I would appreciate your input to the following question:
Is it posible to update a column of a table with the result of a formula involving other columns?
My example is a Table called "Sales"
Store......Product.......Units.........Price........Revenue Share %
A.............Apple..........10 ..........4.00
A.............Sony...........15...........4.20
B.............Apple..........22...........2.50
B.............Sony...........12...........2.80
C.............Apple..........44...........3.50
C.............Sony...........32...........3.80
"Revenue Share %" means the Sales´ contribution of each Product to the Store´s overall Sales.
The formula in each row would be: Revenue Share % = (PricexUnits) of the row / SUM(PricexUnits) of the rows matching the Store of the row under calculation i.e. in the first row, all rows having Store = A.
Can this be done directly in the database, or this should be done with a PHP string including the formula to fill the table?
If both, which is recommended in terms of speed?
Which would be the PHP code to perform this?
I hope to find somebody in the mood to analyze this :-)
MANY thanks for your help!!!
ElBati
Geändert von elbati (26.08.2008 um 23:27:41 Uhr)
|