MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 31st, 2004, 02:55 AM
tttyip tttyip is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 0 tttyip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy How to do this query

hi all, i am trouble with this query requirement.
Suppose i have the two tables:
administrator:
+--------+-------------+--------+
| emp_id | name | gender |
+--------+-------------+--------+
| 20001 | Kate Tse | F |
| 20002 | John Cheung | M |
| 20003 | Kevin Cheng | M |
| 20004 | Richard | M |
+--------+-------------+--------+

adm_work_hours:
+--------+------------+-------+
| emp_id | day | hours |
+--------+------------+-------+
| 20001 | 2004-01-10 | 2.50 |
| 20001 | 2004-01-11 | 2.00 |
| 20002 | 2004-01-10 | 3.00 |
| 20002 | 2004-01-11 | 3.50 |
| 20003 | 2004-01-10 | 8.00 |
+--------+------------+-------+

i need to write a query that find the total working hours
of every administrators. Here is my written query:

SELECT R.emp_id, R.name, sum(hours) as Total_Hours
FROM Administrator as R, Adm_work_hours as S
WHERE R.emp_id = S.emp_id
GROUP BY R.emp_id, R.name
ORDER BY Total_Hours ;


However, I cannot get the work hours of Richard
(emp_id=20004) as 0. How can I also show that his working
hours is zero in the result?


thanks

Reply With Quote
  #2  
Old November 21st, 2004, 04:20 PM
oyejorge oyejorge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 25 oyejorge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 13 sec
Reputation Power: 0
Query that might work. I'm pretty sure it's the LEFT JOIN....

SELECT R.emp_id, R.name, sum(hours) as Total_Hours
FROM Administrator as R LEFT JOIN Adm_work_hours as S on ( R.emp_id = S.emp_id )
GROUP BY R.emp_id, R.name
ORDER BY Total_Hours

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > How to do this query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway