Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Crosstab Query to Summarize Data Horizontally

Posted on 2014-12-09
27
Medium Priority
?
191 Views
Last Modified: 2014-12-10
This is a follow up to the question at the link below.

http://www.experts-exchange.com/Database/MS_Access/Q_28562271.html

I have my schema set up as stated in the above solution using the hybrid approach - one central table for the shared attributes and then EAV tables to describe the non-shared attributes.  In some cases, for certain forms and reports, I need to be able to display data as column headings that are displayed as row headings in this schema.  Instead of having the following information displayed for one property for example:

Type : Residential
Owner : John Smith
Year Built : 2005
Lot Size : 1 acre
Sewer :  Septic
Water : Well

I need to be able to display this data summarized for multiple properties like this :


                   Type                   :  Owner                    :  Year Built          :    Lot size    :    Sewer    :      Water
Property 1   Residential             John Smith                2005                     1 acre           Septic           Well
Property 2   Commercial            Bob Thomas             1987                     5 acres         Public           Public
Property 3   Residential             Mark Jones                2011                    .38 acre        Public           Well


I thought this was what a crosstab query was for but I can't get it to display the actual data elements.  So far it will only let me count, or sum the elements.  I want to actually display them.
0
Comment
Question by:yoducati
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 8
  • 2
27 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40489126
a copy of your tables/db will help..
0
 

Author Comment

by:yoducati
ID: 40489193
This is the best I can do.  I can't post the full db. But these are the essential tables and query.  I need the qryTest to display the information as I mentioned above.
Sample.accdb
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40489230
sorry,  i can't open your A2010 version db.
can you create a new db and just import the tables, query to the newly created db,
save db as Access 2003 database
then upload
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:yoducati
ID: 40489236
It doesnt give me the option to save it as an older version.
0
 

Author Comment

by:yoducati
ID: 40489256
Rather it prohibits me from saving in an older version.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40489949
Based on this specific question, ...are you quite sure the "Hybrid" approach was best?
What you are asking for here now seems to need another design methodology?

I am sure an expert here can "twist" the data to give you what you are after here, ...
...but sometimes it is more efficient to reconsider you design approach... (so hat this is not needed...

Lets see if either of the experts form your previous Q chimes in with more in depth insight...
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40489956
If it were me, ...I would have separated the Vehicles from the Properties,...
But again, lets see if Jim or Pat Chimes in on this...
(I may not have a full grasp of your requirements...)
0
 

Author Comment

by:yoducati
ID: 40489963
Nope not sure.  Working it all out still.  There are many more types than just vehicles and properties.  Those were just examples.  I went with the hybrid approach because it accomplished all I needed it to do very nicely when I though a crosstab query would let me reorganize for views/reporting.  Now I am considering a main table, with many other individual tables for each asset type.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40490084
see the crosstab query "qryTest_Crosstab"
Sample.accdb
0
 

Author Comment

by:yoducati
ID: 40491239
Im not able to open it.  I get a pop up window with random characters in it when I click the link.  This happend to me before but I can't remember what the issue was.  Maybe the version?  Or it might need to be zipped?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40491249
do a right click and select save link as
or use another browser (chrome)
0
 

Author Comment

by:yoducati
ID: 40491254
I dont have access to another browser.  Save as options aren't available.  Let me go back through my other questions and Ill see if I can figure out what happened last time.
0
 

Author Comment

by:yoducati
ID: 40491272
The other ones had to be zipped in order for me to open them.  I think its a combination of the access version, and maybe my browser.
0
 

Author Comment

by:yoducati
ID: 40491523
For what its worth I can't even open the sample database that I posted above.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40491607
export the 4 tables to excel (right click on table > export )

place all excel file in a folder, zipped the folder and upload
0
 

Author Comment

by:yoducati
ID: 40491681
It wont let me upload them
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40491722
upload all the excel files
0
 

Author Comment

by:yoducati
ID: 40491735
0
 

Author Comment

by:yoducati
ID: 40491737
0
 

Author Comment

by:yoducati
ID: 40491738
0
 

Author Comment

by:yoducati
ID: 40491739
0
 

Author Comment

by:yoducati
ID: 40491744
It wouldnt let me do that before either.  I think its mostly my browser causing the issue.  I have no control over that though.  Its supposed to get updated soon.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40491872
post the SQL statement of your query "qryTest"
0
 

Author Comment

by:yoducati
ID: 40491886
SELECT tblAssets.AssetID, tblAttributes.AttributeDescription, tblAssetAttributes.PValue
FROM tblAssetTypes INNER JOIN (tblAttributes INNER JOIN (tblAssets INNER JOIN tblAssetAttributes ON tblAssets.AssetID = tblAssetAttributes.AssetID) ON tblAttributes.AttributeID = tblAssetAttributes.[Attribute ID]) ON tblAssetTypes.TypeID = tblAttributes.TypeID;
0
 

Author Comment

by:yoducati
ID: 40491896
Here is a pdf of the query results as is.  I need the asset ID as a row heading and they should be grouped by asset ID.  Each attribute description should be a column heading.  The PValue should be the data displayed for each asset ID.
qryTest.pdf
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40492011
first create this query

SELECT tblAssets.AssetID, tblAttributes.AttributeDescription, tblAssetAttributes.PValue, tblAssetTypes.TypeDescription
FROM tblAssetTypes INNER JOIN (tblAttributes INNER JOIN (tblAssets INNER JOIN tblAssetAttributes ON tblAssets.AssetID = tblAssetAttributes.AssetID) ON tblAttributes.AttributeID = tblAssetAttributes.[Attribute ID]) ON tblAssetTypes.TypeID = tblAttributes.TypeID;

save as qryTest

then create this query

TRANSFORM First(qryTest.[PValue]) AS FirstOfPValue
SELECT qryTest.[AssetID], qryTest.[TypeDescription]
FROM qryTest
GROUP BY qryTest.[AssetID], qryTest.[TypeDescription]
PIVOT qryTest.[AttributeDescription];
0
 

Author Closing Comment

by:yoducati
ID: 40492115
Thanks for the help. This is exactly what I was trying to do but I didn't realize I needed two queries to do it.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question