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

Join sum to records

Am trying to get a list of all vacation time used by each employee
since 1-1-2002. I can do it with 2 separate queries. The first looks
like...

SELECT e.employee_pk, e.first_name, e.last_name,
a.rate,a.effective_date,
((((YEAR(CURRENT_DATE)-YEAR(effective_date))*12))+(MONTH(CURRENT_DATE)-MONTH(effective_date)))
AS month_count, ((((YEAR(CURRENT_DATE)-2002)*12))+(MONTH(CURRENT_DATE)-1))
AS max_count FROM employee e, hr_vacation_accrual a WHERE
e.employee_pk = a.employee_uid AND e.active=1 AND exempt_status != 'H'
AND exempt_status != 'C' ORDER BY e.last_name, a.effective_date

What the above is doing is getting the employee's name, their accrual
rate (we accrue at various numbers of hours per month based on
seniority), the date the new seniority kicks in, and the number of
months at this rate, as well as how many months there are since
1-1-2002.

It may return something like...

John Smith, 8hours/month, starting 1-1-1999
John Smith, 10hours/month, starting 1-1-2002
John Smith, 13.33hours/month, starting 5-1-2003
Jane Smith.... etc.

I'd like to add to this a hit to the time table to get the sum of
vacation hours that have been taken by the employee. It's ok if it
displays the same sum multiple times.

Here's the query I'd like to work into the above...

select sum(hours) from hr_timesheet
where employee_uid = (the employee_pk above)
and category='VAC'

What I am doing now is running the first query, and then while it
loops, I run the second query over and over for each loop. This is far
from efficient.

Any suggestions would be greatly appreciated.

Thanks,
Don

NOTE: We are not using MySQL 4.1, so I can't do sub-selects.
Jul 19 '05 #1
0 2442

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

Similar topics

4
by: Omavlana | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select b.Account_desc, b.Account, a.CSPL_CSPL from...
5
by: David Logan | last post by:
Hello, I am trying to construct a query across 5 tables but primarily 3 tables. Plan, Provider, ProviderLocation are the three primary tables the other tables are lookup tables for values the...
5
by: Randy Harris | last post by:
Using an outer join, a query can return all records from Table1 and only those matching from Table2 (or vice versa). How can I write a query that will return unmatched records from both sides? ...
9
by: deko | last post by:
I need to create a Recordset of all records that appear in one table but do NOT appear in another. To get the records that appear in BOTH tables, I can do this: SELECT tblEntity.Entity_ID...
0
by: Vendell | last post by:
Join one of Canada's finest business men... Dear entrepreneur colleague: Here is a message from the founder.... Let me introduce myself. My name is Ariel Topf. I am 42 years old and I have...
2
by: kevinjbowman | last post by:
I am by no means a SQl Jedi as will be apparent by my question, but I can usually figure out a select statement on my own. I have one today though that really has me stumped. I am working in...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
3
by: shawnews | last post by:
Ok...I'll first describe briefly what I've done. Working from a paper form with over 200 fields - broken into 10 areas, I created a database with 10 tables. I then created a form using those 10...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
1
by: bluereign | last post by:
Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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.