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

SQL crosstab results in numbers on the 'diagonal'

Hello --

We have annual values for several 'MeasName':
Capital expenditure increment
Growth rate
Subscribers

The table has these fields:
Year
MeasName
MeasValue

We want the result of the crosstab to look like:

MeasName 2005 2006 2007 2008 2009
-----------------------------------------------------------------
CapexIncrement 33 33 41 41 41
GrowthRate 0 .1 .1 .1 .1
Subscribers 42000 46000 50000 55000 60000

The code below results in:
CapexIncremt 33 0 0 0 0
CapexIncremt 0 33 0 0 0
CapexIncremt 0 0 41 0 0
CapexIncremt 0 0 0 41 0
CapexIncremt 0 0 0 0 41
GrowthRate 0 0.1 0 0 0
GrowthRate 0 0 0.1 0 0
GrowthRate 0 0 0 0.1 0
GrowthRate 0 0 0 0 0.1
Subscribers 42000 0 0 0 0
Subscribers 0 46000 0 0 0
Subscribers 0 0 50000 0 0
Subscribers 0 0 0 55000 0
Subscribers 0 0 0 0 60000
SELECT MeasName,
SUM(CASE Yr WHEN 2005 THEN MeasValue ELSE 0 END) AS '2005',
SUM(CASE Yr WHEN 2006 THEN MeasValue ELSE 0 END) AS '2006',
SUM(CASE Yr WHEN 2007 THEN MeasValue ELSE 0 END) AS '2007',
SUM(CASE Yr WHEN 2008 THEN MeasValue ELSE 0 END) AS '2008',
SUM(CASE Yr WHEN 2009 THEN MeasValue ELSE 0 END) AS '2009'
FROM MetricsTime
GROUP BY Yr, MeasName

Can anyone tell me how to change the code to result in the layout we
want?

Thanks for any help.

Larry Mehl

Jul 23 '05 #1
1 1905
Use GROUP BY MeasName ;

--
Anith
Jul 23 '05 #2

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

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
2
by: carl.barrett | last post by:
Hi, I'm back with the same question as I still can't get it to display my data the way I want it to. The table lists information about a perpetrator involved with an anti social behaviour...
2
by: Claus Haslauer | last post by:
Hi, I want to create a crosstab query that looks like this Date | Elevation 1 | Elevation 2 | ... ______________________________________________________________________ Date 1 | xx.y | xx.y...
7
by: newguy | last post by:
I am trying to get the totals of a table by client by type of income. This query will get what I am looking for with each unique combination as a row: SELECT Sales.Client, BillCode.Type,...
13
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
4
by: m.wanstall | last post by:
I have a crosstab query that compiles data for Months of the year. I have a stacked select query on top of that crosstab query that uses the latest 2 months data and exports it to a fixed length...
4
by: rdsandy | last post by:
Hi, I have some code below in VBA for Access 2003 which is on a button called "RentalCrosstabPercTtlQtyMonthLoc_Click". This is a crosstab query which brings up rental items down the side, who...
4
by: Newbie12345 | last post by:
I have a crosstab query which gathers data from a regular table and creates columns for the months in the year with volume for each month. I want to be able export/send the data to a brand new table,...
10
kcdoell
by: kcdoell | last post by:
I have a listbox on a form that uses my crosstab query to display the query results. For the fields that display numbers, the numbers with a zero in the last digit are being dropped. Example $88.80...
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: 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
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
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,...

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.