Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 27th, 2002, 02:12 AM
kalmen kalmen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 kalmen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Query question

Hi ,

I need help in this query
- I have 2 table , Employee (EMP_ID ,DEPT_NO)and EmpPay (EMP_ID,PAY_PERIOD,PAY_AMT)

if I want to produce an output like

___________________________________
DEPT_NO ($500-600) ($600-800)
-----------------------------------
Dept1 count_emp(1) count_emp(7)
Dept2 count_emp(10) count_emp(0)

I want to query how many employee
earning range from $500-600 , $600-800 in each departments ?
How can I achive this ?

Reply With Quote
  #2  
Old September 3rd, 2002, 01:34 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Query question

SELECT DEPT_NO, SUM(IF(PAY_AMT BETWEEN 500 AND 600), 1, 0)), SUM(IF(PAY_AMT BETWEEN 600.01 AND 800), 1, 0)) FROM Employee a JOIN EmpPay b ON a.EMP_ID = b.EMP_ID GROUP BY DEPT_NO ORDER BY DEPT_NO;

Reply With Quote
  #3  
Old September 3rd, 2002, 01:36 PM
jediknight219 jediknight219 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 jediknight219 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Query question

SELECT DEPT_NO, SUM(IF(PAY_AMT BETWEEN 500 AND 600, 1, 0)) AS SUM1, SUM(IF(PAY_AMT BETWEEN 600.01 AND 800, 1, 0)) AS SUM2 FROM Employee AS a JOIN EmpPay AS b ON a.EMP_ID = b.EMP_ID GROUP BY DEPT_NO ORDER BY DEPT_NO;

Doh! Forgot to sign in, so I couldn't edit my post. I put too many parentheses in the first one.

Devshed has a nice article for doing queries like this.
http://www.devshed.com/Server_Side/MySQL/MySQLWiz/page1.html

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Query question


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 2 hosted by Hostway
Stay green...Green IT