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

horizontal display of records

6
consider a table employee with fields empid, ename and department.
records are
Expand|Select|Wrap|Line Numbers
  1. (1,Ram,sales),(2,Abi,Purchase)
consider another table salary with fields empid,month,year,and amount received every month.
records are
Expand|Select|Wrap|Line Numbers
  1. (1,january,2007,2500),(1,february,2007,2300),
  2. (1,march,2007,2800),(1,april,2007,2300),
  3. (1,may,2007,2300),(1,june,2007,3300),
  4. (1,july,2007,2300),(1,august,2007,2300),
  5. (1,september,2007,4300),(1,october,2007,2300),
  6. (1,november,2007,4300),(1,december,2007,4300),
  7. (1,january,2008,4300),(1,february,2008,2300),
  8. (1,march,2008,4300),(1,april,2008,2300),
  9. (1,may,2008,2300),(1,june,2007,2300)
now i have to display the total amount recieved by the employee 1 during the period may2007-jan2008 in the format
Expand|Select|Wrap|Line Numbers
  1. empname |may2007|june2007|july2007|...........|jan2008|total|
  2.         |       |        |        |           |       |     |
  3. Ram     |2300   |2300    |2300    |...........|4300   |     |
  4.  
Dec 30 '08 #1
1 3696
Atli
5,058 Expert 4TB
Hi.

The result layout you posted is very hard to get out of a database, because you are using data as the column headers.
It's not impossible, but far more trouble to accomplish than it is worth.

You should try not to force to much formatting out of a database. It's job is primarily to store data. Your front-end application should be responsible for re-arranging the data into whatever format you want it to be displayed in.

To get the data you wanted, you should simply have the database return a row for each month for each employee, along with the amount for that month.
Expand|Select|Wrap|Line Numbers
  1. +---------+------------+---------+
  2. | empname | date       | ammount |
  3. +---------+------------+---------+
  4. | Abi     | 2007-01-01 |     600 |
  5. | Abi     | 2007-02-01 |    1000 |
  6. | Abi     | 2007-03-01 |     400 |
  7. | Ram     | 2007-01-01 |    2000 |
  8. | Ram     | 2007-02-01 |    1500 |
  9. | Ram     | 2007-03-01 |     500 |
  10. +---------+------------+---------+
To get the total sums as well, you could add a WITH ROLLUP clause to the GROUP BY clause.
Like:
Expand|Select|Wrap|Line Numbers
  1. SELECT empname, date, SUM(ammount)
  2. FROM empsalary
  3. GROUP BY empname, date WITH ROLLUP;
  4.  
Which would return these results:
Expand|Select|Wrap|Line Numbers
  1. +---------+------------+--------------+
  2. | empname | date       | SUM(ammount) |
  3. +---------+------------+--------------+
  4. | Abi     | 2007-01-01 |          600 |
  5. | Abi     | 2007-02-01 |         1000 |
  6. | Abi     | 2007-03-01 |          400 |
  7. | Abi     | NULL       |         2000 |
  8. | Ram     | 2007-01-01 |         2000 |
  9. | Ram     | 2007-02-01 |         1500 |
  10. | Ram     | 2007-03-01 |          500 |
  11. | Ram     | NULL       |         4000 |
  12. | NULL    | NULL       |         6000 |
  13. +---------+------------+--------------+
There you have the total for each employee added, identifiable by the NULL value in the date field, and the total sum from all row, identifiable by the NULL value in both empname and date fields.
Dec 30 '08 #2

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

Similar topics

8
by: Fabian | last post by:
Is there a way to hiode the horizontal (but NOT the vertical) scrollbar? -- -- Fabian Visit my website often and for long periods! http://www.lajzar.co.uk
1
by: Peter Mount | last post by:
Hi When I zoom into my site (http://www.petermount.au.com) with Opera 7.54 the horizontal scrollbar doesn't show when the site image is bigger than my screen. Yet the horizontal scrollbar shows...
14
by: Dave | last post by:
My web site is not particularly theme-based, but it contains an Art Gallery I'd like to display in a different perspective. I would like to horizontally scroll it, rather than vertically - as if...
1
by: camphor | last post by:
hi, I have a single column webpage with a horizontal dropdown menu and am trying to make the nav bar fit across the page, the column is 800px, it looks ok in dreamweaver 8 but when I test it in...
2
by: pbd22 | last post by:
Hi. I am trying to make a horizontal list that counts (downward) and a horizontal list that illustrates the time. Both list should be formatted the same (except for the nomenclature). I seem to...
5
Haitashi
by: Haitashi | last post by:
Hello everyone: I have a CFMenu with the type set to horizontal. I'd like to have the sub-menu items open vertically. Is that possible? Here is my code. I want the Portals sub-menu (Portal A,...
12
by: ryrocks | last post by:
Hello everyone! Im having a little trouble with my horizontal scrolling set of video thumbnails. I've got 6 video thumbnails that the user scrolls through horizontally, I've got this working...
4
by: beary | last post by:
Hi, I have 2 tables as follows: table1 (studid,studfirst,studlast) table2 (resid,studid,resnum,resgrade) In table 1 are 2 records: Record 1: '1','Michael','Jackson' Record 2:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.