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

How to make column data into column headers

I have data from 3 different tables
  • table1
  • table2
  • table3

I currently have a data that looks like this:
TABLE 1

Id | Name | Order
1 | Buchanan | 001
2 | Buchanan | 002
3 | Buchanan | 003
4 | Radhay| 001
5 | Radhay| 002
6 | Reyes| 001
7 | Reyes| 002
8 | Reyes| 003

TABLE 2
1 | 001| Beverage
2 | 002| Condiment
3 | 003| Dessert

TABLE 3
1 | ID001| Buchanan
2 | ID002| Radhay
3 | ID003| Reyes



I want to have some sort of crosstab query that would output my data into this:


ID | Name | Beverage | Condiment | Dessert
ID001 | Buchanan | Yes | Yes | Yes
ID002 | Radhay | Yes | Yes | No
ID003 | Reyes | Yes | Yes | Yes

Can anyone help me create a sql query for this?
Dec 29 '10 #1
9 3017
Rabbit
12,516 Expert Mod 8TB
Look up the syntax for transform pivot by.
Dec 29 '10 #2
But what type of expression do I use to calculate summary values after the word TRANSFORM in the SQL statement?

Since I'm not actually checking for SUM, or MAX...
Dec 29 '10 #3
ck9663
2,878 Expert 2GB
There are a number of samples, here...

Good Luck!!!

~~ CK
Dec 29 '10 #4
Thanks CK... but that's a lot of articles I need to go thru.

I just need to know what values I need to put in the
TRANSFORM
SELECT
FROM
GROUP BY
PIVOT

SQL query...
Dec 29 '10 #5
Rabbit
12,516 Expert Mod 8TB
I would use a count. Then you would know how many of each item they ordered. And a count of zero or a null would mean they didn't order any.
Dec 30 '10 #6
Sorry, fairly new developer here so I'm having trouble creating the SQL...
Dec 30 '10 #7
Rabbit
12,516 Expert Mod 8TB
The transform would be the aggregate function, group by the row fields, and pivot the column groupings.
Dec 31 '10 #8
I'm having problems joining tables. Access said SYNTAX ERROR IN JOIN OPERATION.

TRANSFORM Count(t2.col3) AS Count
SELECT t1.ID, t1.Name, count(t2.col3) AS [Total ]
FROM t1, t2, t3
WHERE t1.Order = t2.col2 AND t1.Name = t3.col3
GROUP BY t1.ID, t1.Name, t2.col3
PIVOT t2.col3
Jan 6 '11 #9
Rabbit
12,516 Expert Mod 8TB
Try using an inner join instead of the cross join.
Jan 6 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gunnar Vøyenli | last post by:
Hi (SQL Server 2000) I have an existing table (t) with a column that is NOT an identity column (t.ID), but it has manually inserted "row numbers". I want to make this column become an identity...
4
by: alederer | last post by:
Hallo! I need to convert the values of a varchar (..) for bit data column to a string which can be stored in a normal varchar column (with additional information). Is there a function in db2...
4
by: Michel Rousseau | last post by:
I have a two column table containing numbers. I would like to make a third column called fieldname "special". In this column I would like to put the following: if column A = column B, then...
0
by: andrewcw | last post by:
After I made a nice application with WINFORM I tried to apply much of the same code, but there are lost of differences. I load the grid colors, column width, column header from a xml data file....
2
by: Sean | last post by:
How can I go about masking the data in a DataGrid Data column? For example, I load a DataSet with somebody's contact information. How can I make the phone number data, which is stored as: ...
3
by: dale.zjc | last post by:
I've got some bizarre behavior going on with my ASP code below. For some strange reason (and I'm a newbie to ASP so it's probably obvious to others) I can't display all the rows of data from the...
1
by: neeraj | last post by:
Hi All Can any give me the code for convert "DataColumn" data type of "DataTable". Even if data table already populated (have data) Actually I am creating one search module which searches the...
2
by: bogie | last post by:
Hello I have some problem to change my column data type in my table property from character(15) to character(100). I use Postgresql 7.4. The problem is I try to make new column with...
2
by: Ken B | last post by:
How can I make a datagrid column into a single row that spans all the other columns? In this case I have a comment field that I want to make as wide as the table but I cannot figure out how to...
2
by: Appu2008 | last post by:
Hi, Iam making a report based on some database values. The fields are displayed in different columns of a table(Iam using php+mysql). My problem is that how can I make the width of a column...
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: 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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.