473,432 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,432 software developers and data experts.

CrossTab Problems

Thank you, I'm making a little headway here as I can get the following code to return the first column for "ChartSales" correctly. Now I'm trying to add 2 more columns that sum different product sales.

The working portion of the code for 1 product is this so far. This gives the correct return.

Expand|Select|Wrap|Line Numbers
  1. SELECT sales_persons.Name, SUM(orders_table.Quantity) AS ChartSales
  2. INNER JOIN sales_persons
  3. ON sales_persons.PersonID = orders_table.PersonID
  4. WHERE orders_table.ProductID = 1
  5. GROUP BY sales_persons.Name
Now i'm trying to add the additional 2 more columns for the other products and mucking it up, I'm not exactly sure how to add the second or third where statement.

Expand|Select|Wrap|Line Numbers
  1. SELECT sales_persons.Name, SUM(orders_table.Quantity) AS ChartSales, SUM(orders_table.Quantity) AS GaugeSales, SUM(orders_table.Quantity) AS MAPSales
  2. FROM orders_table
  3. INNER JOIN sales_persons
  4. ON sales_persons.PersonID = orders_table.PersonID
  5. WHERE orders_table.ProductID = 1
  6.  
  7. ??????????????
  8. ON sales_persons.PersonID = orders_table.PersonID
  9. WHERE orders_table.ProductID = 2
  10.  
  11. ???????????????
  12. ON sales_persons.PersonID = orders_table.PersonID
  13. WHERE orders_table.ProductID = 3
  14.  
  15.  
  16. GROUP BY sales_persons.Name
**Admin Edit**
This question was posted as a response to a previous thread SQL Query Showing Total Sales by Each Person and Each Product.

This starts from a position where the following SQL is available as the source for a CrossTab :
Expand|Select|Wrap|Line Numbers
  1. SELECT   tSR.Name
  2.        , tSR.Region
  3.        , tP.Name
  4.        , SUM(tS.TotalSales) AS TotalProdSales
  5. FROM    ([Sales] AS tS INNER JOIN
  6.          [SalesRep] AS tSR
  7.   ON     tS.PersonNum = tSR.PersonNum) INNER JOIN
  8.          [Products] AS tP
  9.   ON     tS.ProductNum = tP.ProductNum
  10. GROUP BY tSR.Name
  11.        , tSR.Region
  12.        , tP.Name
Jul 31 '10 #1
5 1326
NeoPa
32,556 Expert Mod 16PB
This is tricky.

The first post made sense. I felt the second post also made sense, and provided a viable solution to the question posed in the first. The third post makes no sense to me whatsoever. It neither asks another question, nor in any way modifies the earlier question (not in any way I can see at least). It seems to be reflecting some sort of progression on unspecified areas of your project, but expressed in such a way that is not clear what you're trying to achieve even.

I can't see anything I can do to help except reflect back to you the situation as I see it and hope that you can somehow explain why the question isn't answered, or what you require further.
Aug 2 '10 #2
My apologies for making this overly complicated, what I'm trying to produce is the following chart. The code in post #3 gives me columns 1 and 2, I'm trying to add a 3rd and 4rth column that sums the Sales Person sales and groups it by product like in the 2nd column. however I can't seem to properly add the 3rd and 4rth columns.

Sales results by Sales Person by Product.
Expand|Select|Wrap|Line Numbers
  1. Sales_persons   Product1  Product2  Product3 
  2. SalesRep1        $400       $600     0
  3. SalesRep2        $700        0       $800
  4. SaleRep3          0         0        $1000
  5.  
Aug 2 '10 #3
NeoPa
32,556 Expert Mod 16PB
That makes some sense when considered in isolation, but you still give no relationship to this and the question that this thread is based on (Post #1).
Aug 2 '10 #4
Expand|Select|Wrap|Line Numbers
  1. SalesRep table
  2. ------------
  3. PersonName SalesPersonNumber
  4.  
  5.  
  6. SalesOrders table
  7. ----------
  8. SalesPersonNumber   Sales   ProductID
  9.  
The chart would sum the total sales of each Sales Person and show only their Person Name and the total Sales for that individual by ProductID as per the chart in #5

Thank you for your help in advance, this has been a great learning experience.
Aug 2 '10 #5
NeoPa
32,556 Expert Mod 16PB
I think I can sort of guess what you're talking about. The first question (the question for this thread) was about producing a dataset that could be used in the second question. The second question is quite a departure and needs to be split into a separate thread (I'll do that now for you).

The second question is about a cross-tab type query. I'm pretty inexperienced in such things so I'll simply point you in the direction and leave you to wait for some alternative help or play around with the query wizard and see what you can do for yourself with your new understanding.

Standard queries do not have columns based on the current data. This makes Cross-Tab queries somewhat different.
Aug 2 '10 #6

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

Similar topics

4
by: Greg | last post by:
I am trying to set a perameter for my query but keep getting an error: The Microsoft Jet database engine does not reconize '' as a valid field name or expression. The only difference from other...
1
by: Matthew Wells | last post by:
I have a crosstab query based on anothe query. The base query resultset has no null values in its "Quantity" column. However, when I create the new crosstab query from the base query, the records...
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...
4
by: Judy | last post by:
I'm using Access 2003 and was wondering if it is possible to have a paramater selection within a crosstab query so that I wouldn't need to build a new table. I have a select query that I'm using...
6
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor...
27
by: Bob | last post by:
running access 2k; mdb w/ linked tables to another mdb (front/back-end); trying to run a query that updates a table FROM information from a crosstab query. I AM NOTT trying to update the...
1
by: John | last post by:
Hi I have a report bound to a crosstab query. The problem is that under different conditions crosstab returns different column headings. This causes problems with binding of fields on report. Is...
4
by: mattlightbourn | last post by:
Hi all, I have a problem which has been driving me nuts. Crosstab queries! I have a database witch a few different tables to do with garment manufacturing. I have a table for a client...
3
by: Niranjan | last post by:
I want create a report based on the crosstab query which normally returns about 50 - 60 columns. The columns have names of the counties and they keep changing for every session. Is there a way to...
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
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
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.