473,387 Members | 1,749 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.

Can this format be created?

I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)
Jul 20 '05 #1
10 2110
The only way I can think of is to use programming in a stored procedure
to literally build it 'manually', but that depends on what kind of RDBMS
you're using.

Are you able to store table 2 data in triplets the same as table 1? That
would be easy then.

There seems to be a fight between the data and the way you want to use
it. Are you sure you need to store your data that way? You don't give
any indication of your abilities and it might be that another approach
is better than a solution.
Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #2
The only way I can think of is to use programming in a stored procedure
to literally build it 'manually', but that depends on what kind of RDBMS
you're using.

Are you able to store table 2 data in triplets the same as table 1? That
would be easy then.

There seems to be a fight between the data and the way you want to use
it. Are you sure you need to store your data that way? You don't give
any indication of your abilities and it might be that another approach
is better than a solution.
Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #3
On second thoughts, you need a crosstab query
http://dev.mysql.com/tech-resources/...ard/index.html
Lord Yoda wrote:
The only way I can think of is to use programming in a stored procedure
to literally build it 'manually', but that depends on what kind of RDBMS
you're using.

Are you able to store table 2 data in triplets the same as table 1? That
would be easy then.

There seems to be a fight between the data and the way you want to use
it. Are you sure you need to store your data that way? You don't give
any indication of your abilities and it might be that another approach
is better than a solution.
Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #4
On second thoughts, you need a crosstab query
http://dev.mysql.com/tech-resources/...ard/index.html
Lord Yoda wrote:
The only way I can think of is to use programming in a stored procedure
to literally build it 'manually', but that depends on what kind of RDBMS
you're using.

Are you able to store table 2 data in triplets the same as table 1? That
would be easy then.

There seems to be a fight between the data and the way you want to use
it. Are you sure you need to store your data that way? You don't give
any indication of your abilities and it might be that another approach
is better than a solution.
Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #5
It's similar to a crosstab query format, but yet isn't.
http://dev.mysql.com/tech-resources/...t_version.html
Lord Yoda wrote:
The only way I can think of is to use programming in a stored procedure
to literally build it 'manually', but that depends on what kind of RDBMS
you're using.

Are you able to store table 2 data in triplets the same as table 1? That
would be easy then.

There seems to be a fight between the data and the way you want to use
it. Are you sure you need to store your data that way? You don't give
any indication of your abilities and it might be that another approach
is better than a solution.
Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #6
It's similar to a crosstab query format, but yet isn't.
http://dev.mysql.com/tech-resources/...t_version.html
Lord Yoda wrote:
The only way I can think of is to use programming in a stored procedure
to literally build it 'manually', but that depends on what kind of RDBMS
you're using.

Are you able to store table 2 data in triplets the same as table 1? That
would be easy then.

There seems to be a fight between the data and the way you want to use
it. Are you sure you need to store your data that way? You don't give
any indication of your abilities and it might be that another approach
is better than a solution.
Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #7
it would be quite easy in Access using linked mysql tables. A
combination of a crosstab and a select query....

Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)

Jul 20 '05 #8
it would be quite easy in Access using linked mysql tables. A
combination of a crosstab and a select query....

Bill H wrote:
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)

Jul 20 '05 #9
SELECT Table1.ID,Table1.Data1, Table1.Data2, Table1.Data3,
t2.v20, t2.v30, t2.v40
FROM Table1,
(SELECT ID,
max(CASE WHEN Key = 20 THEN Value ELSE '' END) as v20,
max(CASE WHEN Key = 30 THEN Value ELSE '' END) as v30,
max(CASE WHEN Key = 40 THEN Value ELSE '' END) as v40
FROM Table 2
GROUP BY ID ) as t2
WHERE t2.ID = Table1.ID

"Bill H" <maylar69@hot----.com> wrote in message
news:vf********************************@4ax.com...
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #10
SELECT Table1.ID,Table1.Data1, Table1.Data2, Table1.Data3,
t2.v20, t2.v30, t2.v40
FROM Table1,
(SELECT ID,
max(CASE WHEN Key = 20 THEN Value ELSE '' END) as v20,
max(CASE WHEN Key = 30 THEN Value ELSE '' END) as v30,
max(CASE WHEN Key = 40 THEN Value ELSE '' END) as v40
FROM Table 2
GROUP BY ID ) as t2
WHERE t2.ID = Table1.ID

"Bill H" <maylar69@hot----.com> wrote in message
news:vf********************************@4ax.com...
I have 2 tables:

Table1 contains (among other things):

ID Data1 Data2 Data3
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

Table2 contains (among other things:

ID Key Value
1 20 zzz
1 30 yyy
1 40 xxx
2 20 www
2 30 vvv
2 40 uuu
3 20 ttt
3 30 sss
3 40 rrr

I need a query that returns:

ID Data1 Data2 Data3 Value Value Value
(Key=20) (Key=30) (Key=40)
1 aaa bbb ccc zzz yyy xxx
2 ddd eee fff www vvv uuu
3 ggg hhh iii ttt sss rrr

Any ideas?

Thanks in advance for a push in the right direction! :)


Jul 20 '05 #11

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

Similar topics

6
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but...
1
by: jty202 | last post by:
I know alot of people have the problem with indexed pixel format. I hope someone can show me the solution to this.I am have problem with graphics with the following code giving the error: "A...
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
8
by: ZhangZQ | last post by:
Is there an API to format the HD? I found to use the DeviceIoControl with IOCTL_DISK_FORMAT_TRACKS code can format the floppy, but how to format the HD, I don't want the SHFormatDrvie way. ...
8
by: John Brock | last post by:
I am creating an Excel workbook using VB.NET, and have run into a problem. Excel at times insists on reformatting data that I enter into cells, e.g., converting "01234" to "1234", and this screws...
0
by: Peter Nofelt | last post by:
Hi all, ISSUE: ==================== In SQL 2005 (sp2) I get the following error when preforming a bulk insert with an associated xml format file: "Could not bulk insert. Unknown version of...
3
by: Academia | last post by:
I have a vs2003 project (actually 44 of them) that I want to convert to VS2005 format. To fix a usercontrol file I created the Designer.vb file and moved the Inherited and Class ( change to...
8
by: joemacbusiness | last post by:
Hi All, How do I format printed data in python? I could not find this in the Python Reference Manual: http://docs.python.org/ref/print.html Nor could I find it in Matloff's great tutorial:...
7
by: pamela fluente | last post by:
My numericUpDowns show numbers in the format 1.500,56 (italy). Instead, I need *invariantly* that they show and accept the format 1,500.56, as in the USA. What's the right way to do that? I...
1
by: Joe Humburg | last post by:
Hi everyone, Looking for some help or ideas, on the folloiwng problem. Have an Access 2003 application that creates an Excel file containing data from an Access parameter query. This is...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.