PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > BIG PROBLEM
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
BIG PROBLEM

Réponse
 
LinkBack Outils de la discussion
Vieux 14/02/2008, 20h14   #1
crashbangboom@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut BIG PROBLEM

Well maybe not for you guru's...

MySQL 5.0.45

I have a table that has years of certification data that ties it to
it's parent with an index number...I want to iterate through the
records, calculate a percentage of change, and place it in a field
(Deviation) that has been previously created:

ID = 1 CalibrationDate = 2001-02-14 Volume = 15.123456
Deviation = NULL
ID = 1 CalibrationDate = 2003-01-23 Volume = 15.123547
Deviation = 0.0006
ID = 1 CalibrationDate = 2005-03-18 Volume = 15.123598
Deviation = 0.0003

After the Deviation has been calculated and placed, I want to compare
each with the previous to determine if the the accepted tolerance has
been exceeded (>=0.04%) and if it has place a "Y" in another
previously created field (OutOfTol)...

I'm no database expert especially with problems of this nature...Any
will be greatly appreciated...

Thanks in advance for your attention...!!!...

Dave
  Réponse avec citation
Vieux 14/02/2008, 20h46   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: BIG PROBLEM

On Thu, 14 Feb 2008 20:14:17 +0100, <crashbangboom@gmail.com> wrote:
> Well maybe not for you guru's...


In future, you might want to use a better topic then 'BIG PROBLEM'. The
fact you have a question is usually clear by starting a thread, having a
descriptive subject draws more people in.


> MySQL 5.0.45
>
> I have a table that has years of certification data that ties it to
> it's parent with an index number...I want to iterate through the
> records, calculate a percentage of change, and place it in a field
> (Deviation) that has been previously created:
>
> ID = 1 CalibrationDate = 2001-02-14 Volume = 15.123456
> Deviation = NULL
> ID = 1 CalibrationDate = 2003-01-23 Volume = 15.123547
> Deviation = 0.0006


Euhm, deviation is about 0.000006612%

> ID = 1 CalibrationDate = 2005-03-18 Volume = 15.123598
> Deviation = 0.0003


> After the Deviation has been calculated and placed, I want to compare
> each with the previous to determine if the the accepted tolerance has
> been exceeded (>=0.04%) and if it has place a "Y" in another
> previously created field (OutOfTol)...
>


I assume a deviation is to be calculated as a percentage change from the
last (highest date) volume ((old.volume - new.Volume) / old.volume) * 100,
of the same ID? If CalibrationDate is never NULL, you might want to use
this (be warned: untested):

UPDATE tablename o
JOIN tablename j
ON o.ID = j.ID
AND j.CalibrationDate < o.CalibrationDate
LEFT JOIN tablename x
ON o.ID = x.ID
AND x.CalibrationDate > o.CalibrationDate
SET o.Deviation = ((o.Volume - j.Volume)/o.Volume) * 100,
o.OutOfTol = IF(((o.Volume - j.Volume)/o.Volume) > 0.0004,'Y','N')
WHERE x.ID IS NULL
--
Rik Wasmus
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h00.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08795 seconds with 10 queries