473,396 Members | 2,081 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,396 software developers and data experts.

Subtotals and Totals

I have a database that tracks the vacation time of each employee of the
company that I work for. Everything works great and totals all of the
vacation time that has been used. Could someone give me a little
guidance on how I could get a subtotal for each employee and then total
all of the subtotals? I would like to list employee 1's time and total
it, then employee 2's time and total it and so on. Then total all of
the subtotals. Not sure where to start to create the loop for each
different employee.

Thanks in advance for your help,

Greg

Mar 25 '06 #1
3 4371
On Fri, 24 Mar 2006 18:23:03 -0800, Greg wrote:
I have a database that tracks the vacation time of each employee of the
company that I work for. Everything works great and totals all of the
vacation time that has been used. Could someone give me a little
guidance on how I could get a subtotal for each employee and then total
all of the subtotals? I would like to list employee 1's time and total
it, then employee 2's time and total it and so on. Then total all of
the subtotals. Not sure where to start to create the loop for each
different employee.

Thanks in advance for your help,

Greg

Here is a select from the famous EMP & DEPT tables which does something
similar to what you want:

WITH sums AS
(SELECT deptno,
SUM(sal) AS salary
FROM emp
GROUP BY rollup(deptno))
SELECT d.deptno,
d.loc,
s.salary
FROM sums s,
dept d
WHERE s.deptno = d.deptno(+)

Results look like this:

DEPTNO LOC SALARY
---------- ------------- ----------
10 NEW YORK 8750
20 DALLAS 10875
30 CHICAGO 9400
29025

SQL>
The critical part, which provides subtotals and the final total is
"GROUP BY ROLLUP". This, however, depends on the type of the database
you are using. The statement above is from Oracle RDBMS, with version
being at least 9i. In lower versions subquery factoring (WITH ...) doesn't
work. I'm not sure about the GROUP BY ROLLUP part either. So, if your
database is not Oracle, get yourself Oracle 10XE. It is free, you can
stuff 4GB in it and you can do things like the query above with it.
It supports subquery factoring, group by rollup and much, much more.

--
http://www.mgogala.com

Mar 25 '06 #2
Sorry, I should have given more specifics. I'm using PHP to access a
MySQL database on a Windows 2000 server. What I have developed gives a
long list of employee names, dates and hours with a total at the
bottom. What I would like to do is have a break between each employee
and total their hours, then have the grand total at the bottom.

Thanks,

Greg

Mar 26 '06 #3
On Sat, 25 Mar 2006 18:47:38 -0800, Greg wrote:
Sorry, I should have given more specifics. I'm using PHP to access a
MySQL database on a Windows 2000 server. What I have developed gives a
long list of employee names, dates and hours with a total at the
bottom. What I would like to do is have a break between each employee
and total their hours, then have the grand total at the bottom.


Please disregard my reply. Wrong kind of database.

--
http://www.mgogala.com

Mar 27 '06 #4

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

Similar topics

2
by: Scott | last post by:
How can you show SUBTOTALS in the same column as the data, NOT in a separate column? I need to SUBTOTAL in the same column as one of the the data columns, like the subtotals 700 and 800 under...
1
by: Andy V | last post by:
Hi. I've got a multi page report of my monthly purchases. I'd like a running total (month to date) at the end of each page and to have that total at the top of the following page. So far all I can...
3
by: John Baker | last post by:
Hi: I have a situation where I have a series of time records (one or more per day) for a number of projects. Each record has an identification for the activity conducted during the period...
0
by: Mark | last post by:
Is there a way to put a subtotal in a datagrid? For example, let's say I have a datagrid of sales for a given year. No paging. I've used the ItemDataBound event of the datagrid to add totals at...
2
by: Richard Grene | last post by:
I am creating an Excel spreadsheet using a query function in my vb code. This works fine. I can format the columns but dont know how to create subtotals and a grand total. Thanks, Richard
4
by: Jerry LeVan | last post by:
Is is possible, via some clever sql coding ( perhaps with PL/pgsql) to get subtotals to appear in a selection, ie If I have a query: select * from checks order by category I would like the have...
0
by: Paul Ilacqua | last post by:
I'm using VB .NET and I'm trying to "roll my own" report subtotals. I'm building a string from a datareader top pass to a reporting class and I want to break and subtotal QTY at each change in...
5
prn
by: prn | last post by:
Hi folks, I'm looking for a little advice here. I need to create a report that is totals only, with no detail records. I have a database with a lot of individuals (people) and the report has to...
2
by: =?Utf-8?B?SHV0dHk=?= | last post by:
I have searched the net but have been unable to find a solution to subtotaling in a gridview. I have a gridview that is bounded to sqldatasource where I would like to subtotal rows throughout the...
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: 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?
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.