473,471 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question about creating columns from data in rows

Sol
If I have data in the following format in a database

LE Amount BS Class
1 10 Asset
1 15 Liability
1 20 Asset
1 12 Liability
2 45 Asset
2 74 Asset
2 12 Liability
I want to extract the sum of each LE by BS Class, but I want the BS
class in two seperate columns.

So
LE Assets Liablities
1 30 27
2 119 12
What SQL code can I use to do that.

NB I have run two seperate queries to return Assets & liabilities, but
if one LE has no assets the two tables get out of sequence. I really
need it to say 0 assets vs the liabilities.

Oct 5 '07 #1
2 1542
Hi Sol,

If your data is in the format you describe then you can use a crossTab
query to get the results you desire. Just click on New Query and select
Crosstab from the list. A wizard will come up to guide you through the
query creation process. Select LE for Row Heading, select BS Class for
Column Heading, and select Sum for Amount. You may want to uncheck the
"Include Sum Total" in the lower left corner of the dialog that contains
the list with the Sum function.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Oct 5 '07 #2
Use a crosstab query (Crosstab on Query menu, in query design.)

LE is your Row Heading
BS Class is your Column Heading.
Amount is your Value, and it looks like you want Sum in the Total row.

Once you get the basics of crosstab queries down, here's some more involved
techniques:
http://allenbrowne.com/ser-67.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Sol" <so***********@citi.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
If I have data in the following format in a database

LE Amount BS Class
1 10 Asset
1 15 Liability
1 20 Asset
1 12 Liability
2 45 Asset
2 74 Asset
2 12 Liability
I want to extract the sum of each LE by BS Class, but I want the BS
class in two seperate columns.

So
LE Assets Liablities
1 30 27
2 119 12
What SQL code can I use to do that.

NB I have run two seperate queries to return Assets & liabilities, but
if one LE has no assets the two tables get out of sequence. I really
need it to say 0 assets vs the liabilities.
Oct 6 '07 #3

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

Similar topics

18
by: Guinness Mann | last post by:
Greetings, I think I saw an article yesterday in which you told someone not to make an Identity column a primary key. I seem to remember you saying something like "It undermines the entire...
0
by: Tim Brooks | last post by:
All, I'm hoping one of you Xml or Data gurus can offer an opinion. I'm working on an app to basically compare two semi-structured data files (e.g. Excel / CSV) to one another. But I need to...
7
by: tony | last post by:
I'm designing a database which will store test data from a scientific instrument. There are approximately 300 variables which can be collected from this device, although not all tests will conatin...
0
by: Christopher | last post by:
Hello, First, I appologize for the length but I want to get all the facts down so as not to waste any time :) I'm trying to allow the user of my C# app to copy a DataGrid full of double values...
5
by: JL | last post by:
Hi, I was asked the following question at work: "Assume that you have 5000 columns and 5000 rows of data. You take these data from the database and need to show them in a table. Before...
7
by: Ryan | last post by:
I'm in the process of learning more about building my ASP.NET website to use my SQL datastore and am a bit confused about how ADO.NET works with ASP.NET. This Microsoft article implies that using...
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...
0
by: Jerry | last post by:
Hi, I am getting a list text files and readig each of them and breaking down each file string into a number of varibles. I want to create each table, if it does not exist and add or update the...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
20
by: xiao | last post by:
Hi~ every one~ I have a queston about fread function. if i have a code like this: (nscrdh and data are defined as two dementional arrays and both of them were stored in the same binary file) ...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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...
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.