473,666 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1914
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
7564
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 want them to do as little as possible when they run their reports. I have a crosstab query that displays usage of items for each month. It looks pretty much like this: ITEM DESC UM 12/02 1/03 2/03 3/03 ...ETC. 1 Solution ...
2
2250
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 order. The table contains personal information about the individual as well as (here is where the letter dates comes in:) e.g.
2
5956
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 Date 2 | xx.y | xx.y xx.y are measurements taken at different dates at different elevations. xx.y and elevation happen to be in the same format (meters).
7
1902
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, Sum(Sales.Amount) FROM Invoice_Details INNER JOIN BillCode ON Sales.BillCode = BillCode.id GROUP BY Client, Type;
13
17136
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 launching Excel for data viewing. I'd prefer the user stay in Access. Creating dynamic crosstab queries is pretty simple. The problem is that the column count may shrink or grow depending on the filter.
4
6472
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 flat file. Ideally I would like to be able to just select the Last 2 Columns of the Crosstab query as inputs to the Select query WITHOUT having to go in month after month and manually change it... I may be asking a bit much here but is there a...
4
2482
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 rents along the top, the rental month and total number of each item on that month as rows next to the item, something like this: Item TotalQty Month Renter1 Renter2 .... PC 234 Aug-2007 2.33 4.55 ...
4
36205
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, which would keep the new formating with the months as fields. So basicall i want to create a table from that crosstab query that looks identical to the query. I tried using a make-table query but this just puts all the data back into the way the...
10
2031
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 is displayes as $88.8. I have the field set as a numeric/double. The interesting thing is that the raw data file has the zeros on the end. I am thinking I need to resolve the formating issue in the query itself. Does anybody have any ideas?
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5666
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.