PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > big query question
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
big query question

Réponse
 
LinkBack Outils de la discussion
Vieux 18/04/2006, 21h23   #1
Fred S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut big query question

Hi,
I am working on a database of time series, where the main table looks
like this
date | id | value
but i have something like several thousands of id's and several
thousands of dates as well
my goal is to obtain
date in the format of a matrix with the rows being the dates and each
column contains the values for a certain ID.
Now obviously I could write a join statement, but i dont think that its
the best way.
I there a way to dynamiccaly create these joins ? maybe using a stored
procedure.

Many Thanks

Fred

  Réponse avec citation
Vieux 19/04/2006, 20h51   #2
onedbguru@firstdbasource.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: big query question

in google search for oracle pivot table

  Réponse avec citation
Vieux 20/04/2006, 16h49   #3
onedbguru@firstdbasource.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: big query question

also mysql pivot table

  Réponse avec citation
Vieux 20/04/2006, 17h38   #4
onedbguru@firstdbasource.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: big query question

also mysql pivot table

  Réponse avec citation
Vieux 20/04/2006, 18h43   #5
Bill Karwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: big query question

Fred S wrote:
> Hi,
> I am working on a database of time series, where the main table looks
> like this
> date | id | value
> but i have something like several thousands of id's and several
> thousands of dates as well
> my goal is to obtain
> date in the format of a matrix with the rows being the dates and each
> column contains the values for a certain ID.
> Now obviously I could write a join statement, but i dont think that its
> the best way.
> I there a way to dynamiccaly create these joins ? maybe using a stored
> procedure.


See the article here:
http://dev.mysql.com/tech-resources/...ard/index.html

So you could make a quey such as this one:

SELECT t.date,
GROUP_CONCAT(IF(t.id = 1, t.value, NULL)) AS `ID 1`,
GROUP_CONCAT(IF(t.id = 2, t.value, NULL)) AS `ID 2`,
GROUP_CONCAT(IF(t.id = 3, t.value, NULL)) AS `ID 3`
FROM mytable AS t
GROUP BY t.date, t.id

Unfortunately, this solution for the crosstab query in MySQL requires
that you hard-code the columns. This is in part because there's no way
to make a SQL query have a dynamic number of columns, or to use a
variable in a column alias.

You can run a query prior to this, to get a list of distinct id values,
and then in your application dynamically construct the query as a
string, then execute it.

You may have to choose a subset of id values, because I don't think you
can have an unlimited number of fields in a select-list. I could only
find a reference that MyISAM tables can have a max number of columns of
3392, but this doesn't mean that the same limit applies to fields in a
query.

Regards,
Bill K.
  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 22h06.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09097 seconds with 13 queries