|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ? |
|
#2
|
|||
|
|||
|
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;
|
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Query question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|