473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Apr 18 '06 #1
4 2987
in google search for oracle pivot table

Apr 19 '06 #2
also mysql pivot table :)

Apr 20 '06 #3
also mysql pivot table :)

Apr 20 '06 #4
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.
Apr 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
3
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.