473,385 Members | 1,740 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,385 software developers and data experts.

Creating a report with customers as rows and products as columns

A table named SELL have 3 fields---
customer_id,product,unit

the rows of the table ---------
customer_id----product---unit
---------------------------------------------
1-----------------toy--------------15
2-----------------toy--------------20
3----------------food-------------25
4----------------dress---------------10
2----------------toy----------------12
2----------------food----------------5
1----------------food---------------3


I want to make a sql so that the data will be shown as followings:

customer_id------toy--------food----dress-----TOTAL
-------------------------------------------------------------
1----------------------15--------3---------0----------18
2---------------------32--------5----------0----------37
3---------------------0----------25--------0----------25
4---------------------0----------0----------10--------10
5--------------------0-----------0-----------0----------0
_____________________________________
TOTAL------------47--------33--------10----------90


customer_id is the foreign key which refers another table Customer.
and product is also foreign key which refers another table PRODUCT.

Now please help me to make the query.
Sep 5 '07 #1
3 1353
r035198x
13,262 8TB
A table named SELL have 3 fields---
customer_id,product,unit

the rows of the table ---------
customer_id----product---unit
---------------------------------------------
1-----------------toy--------------15
2-----------------toy--------------20
3----------------food-------------25
4----------------dress---------------10
2----------------toy----------------12
2----------------food----------------5
1----------------food---------------3


I want to make a sql so that the data will be shown as followings:

customer_id------toy--------food----dress-----TOTAL
-------------------------------------------------------------
1----------------------15--------3---------0----------18
2---------------------32--------5----------0----------37
3---------------------0----------25--------0----------25
4---------------------0----------0----------10--------10
5--------------------0-----------0-----------0----------0
_____________________________________
TOTAL------------47--------33--------10----------90


customer_id is the foreign key which refers another table Customer.
and product is also foreign key which refers another table PRODUCT.

Now please help me to make the query.

If you are going to have as many columns as products, how are you going to know how many columns you will need?
Sep 5 '07 #2
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Sep 5 '07 #3
Actually I am making a database software.
Now I just create a table with the fields customer and with distinct product name.
that means if number of distinct product=5 then I create a table with 6 column.
Then I insert rows for every customer and curresponding total product wise unit for each customer.

I have done it in the run time of the software.

But I think it is not the actual way.

Yes there any other efficient way?

Thanks to all.
BYE
Sep 6 '07 #4

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

Similar topics

4
by: Jeremy Weiss | last post by:
Thanks to much help from everyone in my previous thread, I've made it a pretty fair ways into my billing/invoicing db. I'm now needing a way to cycle through all the records in a table and create...
2
by: Hohn Upshew | last post by:
I need some help to build a report enumerating the products in descending order depending on the sum of liters. In this way i can view the top products sold for a given period.But i fail to do...
2
by: Andrea | last post by:
I'm having some difficulty creating a report in Access and I need some suggestions. My company issues "Return Authorizations" when customers need to return products. A customer calls in and we...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
2
by: jburris | last post by:
In my current database, I have a single table which contains order information such as product, unit price and payment. The payment for each product is entered in and subtotals and totals are...
4
by: RSH | last post by:
Hi, I have a situation where I have created a little application that makes an Access database from a SQL Database for reporting purposes. it does the job well, but it seems a bit slow. Is...
3
by: steve | last post by:
Hi All I have a VB.net 2005 app which uses MS Report Viewer to create reports Occassionally I get the following error when changing to a different report User code running on thread 196 has...
0
by: koonda | last post by:
Hi guys, I posted a message before and I got some help from the forum. I have a database in SQL Server and I wanted to create a web interface in C#. I had 4 Listbox controls and a Textbox and two...
6
by: firefighter17103 | last post by:
Hi All, I am new to MS Access 07, & do not know any VB, on a new business adventure. I am running Office07 on Vista Home Premium. I am in the process of creating a database that in the end I...
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: 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: 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...
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.