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 > time series data storage
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
time series data storage

Réponse
 
LinkBack Outils de la discussion
Vieux 04/02/2008, 15h52   #1
Dan Braun
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut time series data storage

Hi all, I am trying to get my head around changing the format of some
data for import into a simulation tool.
I am storing arisings values for several machines for several years.

The data is in a table like this:

id name year value
1 machine 1 2008 10
2 machine 2 2008 23
3 machine 3 2008 34
4 machine 1 2009 120
5 machine 3 2009 233
6 machine 1 2010 292
7 machine 2 2010 34
8 machine 3 2010 102

I need to be able to output it like this:
2008 2009 2010
machine 1 10 120 292
machine 2 23 NULL 34
machine 3 34 233 102

I have searched the net, but think im looking for the wrong terms,
this must be possible with some funky inner join thing, but I have to
admit to being a bit stumped.

Can anyone shed any light on this?

Cheers
Dan
  Réponse avec citation
Vieux 04/02/2008, 16h37   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: time series data storage

On 4 Feb, 15:52, Dan Braun <danbra...@gmail.com> wrote:
> Hi all, I am trying to get my head around changing the format of some
> data for import into a simulation tool.
> I am storing arisings values for several machines for several years.
>
> The data is in a table like this:
>
> id name year value
> 1 machine 1 2008 10
> 2 machine 2 2008 23
> 3 machine 3 2008 34
> 4 machine 1 2009 120
> 5 machine 3 2009 233
> 6 machine 1 2010 292
> 7 machine 2 2010 34
> 8 machine 3 2010 102
>
> I need to be able to output it like this:
> 2008 2009 2010
> machine 1 10 120 292
> machine 2 23 NULL 34
> machine 3 34 233 102
>
> I have searched the net, but think im looking for the wrong terms,
> this must be possible with some funky inner join thing, but I have to
> admit to being a bit stumped.
>
> Can anyone shed any light on this?
>
> Cheers
> Dan


Something like:
SELECT
a1.name,
a1.value 2008,
a2.value 2009,
a3.value 2010
FROM table a1
LEFT JOIN table a2 ON a1.name = a2.name AND a2.year = '2009'
LEFT JOIN table a3 ON a1.name = a3.name AND a3.year = '2010'
WHERE a1.year = '2008'
  Réponse avec citation
Vieux 04/02/2008, 17h09   #3
Dan Braun
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: time series data storage

On 4 Feb, 16:37, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 4 Feb, 15:52, Dan Braun <danbra...@gmail.com> wrote:
>
>
>
>
>
> > Hi all, I am trying to get my head around changing the format of some
> > data for import into a simulation tool.
> > I am storing arisings values for several machines for several years.

>
> > The data is in a table like this:

>
> > id name year value
> > 1 machine 1 2008 10
> > 2 machine 2 2008 23
> > 3 machine 3 2008 34
> > 4 machine 1 2009 120
> > 5 machine 3 2009 233
> > 6 machine 1 2010 292
> > 7 machine 2 2010 34
> > 8 machine 3 2010 102

>
> > I need to be able to output it like this:
> > 2008 2009 2010
> > machine 1 10 120 292
> > machine 2 23 NULL 34
> > machine 3 34 233 102

>
> > I have searched the net, but think im looking for the wrong terms,
> > this must be possible with some funky inner join thing, but I have to
> > admit to being a bit stumped.

>
> > Can anyone shed any light on this?

>
> > Cheers
> > Dan

>
> Something like:
> SELECT
> a1.name,
> a1.value 2008,
> a2.value 2009,
> a3.value 2010
> FROM table a1
> LEFT JOIN table a2 ON a1.name = a2.name AND a2.year = '2009'
> LEFT JOIN table a3 ON a1.name = a3.name AND a3.year = '2010'
> WHERE a1.year = '2008'- Hide quoted text -
>
> - Show quoted text -


hi! thats what I cam up with, the trouble is that the actual dataset
is for 30 odd machines for 160 years, so the sql would look
gargantuan, I wondered if there was a way of doing it recursively, or
generating rows like
10 120 292 as some kind of subquery (select year from
datatable where name = (select distinct name from datatable))
is this possible?

I wonder if I might have overnormalised the data somewhat, but quite a
few of the machines wont have arisings for several years, leaving lots
of whitespace in a table where each machine has a column for every
year.

Dan
  Réponse avec citation
Vieux 04/02/2008, 17h16   #4
Dan Braun
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: time series data storage

On 4 Feb, 17:09, Dan Braun <danbra...@gmail.com> wrote:
> On 4 Feb, 16:37, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 4 Feb, 15:52, Dan Braun <danbra...@gmail.com> wrote:

>
> > > Hi all, I am trying to get my head around changing the format of some
> > > data for import into a simulation tool.
> > > I am storing arisings values for several machines for several years.

>
> > > The data is in a table like this:

>
> > > id name year value
> > > 1 machine 1 2008 10
> > > 2 machine 2 2008 23
> > > 3 machine 3 2008 34
> > > 4 machine 1 2009 120
> > > 5 machine 3 2009 233
> > > 6 machine 1 2010 292
> > > 7 machine 2 2010 34
> > > 8 machine 3 2010 102

>
> > > I need to be able to output it like this:
> > > 2008 2009 2010
> > > machine 1 10 120 292
> > > machine 2 23 NULL 34
> > > machine 3 34 233 102

>
> > > I have searched the net, but think im looking for the wrong terms,
> > > this must be possible with some funky inner join thing, but I have to
> > > admit to being a bit stumped.

>
> > > Can anyone shed any light on this?

>
> > > Cheers
> > > Dan

>
> > Something like:
> > SELECT
> > a1.name,
> > a1.value 2008,
> > a2.value 2009,
> > a3.value 2010
> > FROM table a1
> > LEFT JOIN table a2 ON a1.name = a2.name AND a2.year = '2009'
> > LEFT JOIN table a3 ON a1.name = a3.name AND a3.year = '2010'
> > WHERE a1.year = '2008'- Hide quoted text -

>
> > - Show quoted text -

>
> hi! thats what I cam up with, the trouble is that the actual dataset
> is for 30 odd machines for 160 years, so the sql would look
> gargantuan, I wondered if there was a way of doing it recursively, or
> generating rows like

10 120 292 as some kind of subquery (select value from
datatable where date = (select distinct date from datatable))

> is this possible?
>
> I wonder if I might have overnormalised the data somewhat, but quite a
> few of the machines wont have arisings for several years, leaving lots
> of whitespace in a table where each machine has a column for every
> year.
>
> Dan- Hide quoted text -
>
> - Show quoted text -


  Réponse avec citation
Vieux 04/02/2008, 19h02   #5
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: time series data storage

On Feb 4, 12:09 pm, Dan Braun <danbra...@gmail.com> wrote:
> On 4 Feb, 16:37, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
> > On 4 Feb, 15:52, Dan Braun <danbra...@gmail.com> wrote:

>
> > > Hi all, I am trying to get my head around changing the format of some
> > > data for import into a simulation tool.
> > > I am storing arisings values for several machines for several years.

>
> > > The data is in a table like this:

>
> > > id name year value
> > > 1 machine 1 2008 10
> > > 2 machine 2 2008 23
> > > 3 machine 3 2008 34
> > > 4 machine 1 2009 120
> > > 5 machine 3 2009 233
> > > 6 machine 1 2010 292
> > > 7 machine 2 2010 34
> > > 8 machine 3 2010 102

>
> > > I need to be able to output it like this:
> > > 2008 2009 2010
> > > machine 1 10 120 292
> > > machine 2 23 NULL 34
> > > machine 3 34 233 102

>
> > > I have searched the net, but think im looking for the wrong terms,
> > > this must be possible with some funky inner join thing, but I have to
> > > admit to being a bit stumped.

>
> > > Can anyone shed any light on this?

>
> > > Cheers
> > > Dan

>
> > Something like:
> > SELECT
> > a1.name,
> > a1.value 2008,
> > a2.value 2009,
> > a3.value 2010
> > FROM table a1
> > LEFT JOIN table a2 ON a1.name = a2.name AND a2.year = '2009'
> > LEFT JOIN table a3 ON a1.name = a3.name AND a3.year = '2010'
> > WHERE a1.year = '2008'- Hide quoted text -

>
> > - Show quoted text -

>
> hi! thats what I cam up with, the trouble is that the actual dataset
> is for 30 odd machines for 160 years, so the sql would look
> gargantuan, I wondered if there was a way of doing it recursively, or
> generating rows like
> 10 120 292 as some kind of subquery (select year from
> datatable where name = (select distinct name from datatable))
> is this possible?
>
> I wonder if I might have overnormalised the data somewhat, but quite a
> few of the machines wont have arisings for several years, leaving lots
> of whitespace in a table where each machine has a column for every
> year.
>
> Dan


I would recommend doing the "cross-tab" in something other than SQL.
If you don't know how many years you're going to have then you've
designed your tables correctly. It's just that SQL isn't all that
great at doing this sort of thing. I don't know what you're doing
with this data, but if you're using something like PHP it would be
simple enough to do it there.
  Réponse avec citation
Vieux 04/02/2008, 22h42   #6
Dan Braun
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: time series data storage

On Feb 4, 7:02 pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
> On Feb 4, 12:09 pm, Dan Braun <danbra...@gmail.com> wrote:
>
>
>
> > On 4 Feb, 16:37, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > On 4 Feb, 15:52, Dan Braun <danbra...@gmail.com> wrote:

>
> > > > Hi all, I am trying to get my head around changing the format of some
> > > > data for import into a simulation tool.
> > > > I am storing arisings values for several machines for several years.

>
> > > > The data is in a table like this:

>
> > > > id name year value
> > > > 1 machine 1 2008 10
> > > > 2 machine 2 2008 23
> > > > 3 machine 3 2008 34
> > > > 4 machine 1 2009 120
> > > > 5 machine 3 2009 233
> > > > 6 machine 1 2010 292
> > > > 7 machine 2 2010 34
> > > > 8 machine 3 2010 102

>
> > > > I need to be able to output it like this:
> > > > 2008 2009 2010
> > > > machine 1 10 120 292
> > > > machine 2 23 NULL 34
> > > > machine 3 34 233 102

>
> > > > I have searched the net, but think im looking for the wrong terms,
> > > > this must be possible with some funky inner join thing, but I have to
> > > > admit to being a bit stumped.

>
> > > > Can anyone shed any light on this?

>
> > > > Cheers
> > > > Dan

>
> > > Something like:
> > > SELECT
> > > a1.name,
> > > a1.value 2008,
> > > a2.value 2009,
> > > a3.value 2010
> > > FROM table a1
> > > LEFT JOIN table a2 ON a1.name = a2.name AND a2.year = '2009'
> > > LEFT JOIN table a3 ON a1.name = a3.name AND a3.year = '2010'
> > > WHERE a1.year = '2008'- Hide quoted text -

>
> > > - Show quoted text -

>
> > hi! thats what I cam up with, the trouble is that the actual dataset
> > is for 30 odd machines for 160 years, so the sql would look
> > gargantuan, I wondered if there was a way of doing it recursively, or
> > generating rows like
> > 10 120 292 as some kind of subquery (select year from
> > datatable where name = (select distinct name from datatable))
> > is this possible?

>
> > I wonder if I might have overnormalised the data somewhat, but quite a
> > few of the machines wont have arisings for several years, leaving lots
> > of whitespace in a table where each machine has a column for every
> > year.

>
> > Dan

>
> I would recommend doing the "cross-tab" in something other than SQL.
> If you don't know how many years you're going to have then you've
> designed your tables correctly. It's just that SQL isn't all that
> great at doing this sort of thing. I don't know what you're doing
> with this data, but if you're using something like PHP it would be
> simple enough to do it there.


the data is being presented in php, but also read into a simulation
tool, which is where i started having problems with it as the easiest
way to feed it into the model would be to sort of reconstitute the
data back into a table as i laid it out above. I will have to have a
more careful think about a set of big loops or something to populate
this table.

thanks for the .

Dan
  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 04h15.


É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,72269 seconds with 14 queries