|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
count clause in sql query
I use following query.
SELECT employees.empno, employees.name, approvals.contractno, assignments.acontract,assignments.aposit, assignments.astrdate, assignments.aenddate FROM (employees INNER JOIN approvals ON employees.empno=approvals.empno) INNER JOIN assignments ON employees.empno=assignments.empno data retrieve from the sql server tables like this. empno name aposit contractno acontract --------------------------------------------------------- 1234 Martin Engineer 2016 229 7890 Jones *** Engr 2002 221 1234 Martin Engineer 2016 222 1590 Peter Sr.Engr 894 982 1234 Martin Engineer 2010 985 1590 Peter Sr.Engr 229 2016 1234 Martin Engineer 2016 3010 1590 Peter Sr.Engr 229 2016 7890 Jones *** Engr 2002 229 4567 George Engineer 2015 222 7800 Mathew Sureyor 2017 225 ........... and so on....... contractno means approvals.contractno acontract means assignments.acontract some employee are working four contracts, some are three and some are two and remaining employees working only one contract. How can data can retreive from the above query that it count the employee that it working four contract, three contracts, two contract and one contract etc. data retrieve like this. empno..name....aposit...contractno..acontract count (working acontract) ---------------------------------------------------------- 1234...Martin...Engineer....2016....229........4 1234...Martin...Engineer....2016....222 1234...Martin...Engineer....2010....985 1234...Martin...Engineer....2016....3010 1590...Peter....Sr.Engr.....894.....982........3 1590...Peter....Sr.Engr.....229.....2016 1590...Peter....Sr.Engr.....229.....2016 7890...Jones....*** Engr....2002....221........2 7890...Jones....*** Engr....2002....229 4567...George...Engineer....2015....222........1 7800...Mathew...Sureyor.....2017....225........1 ........... and so on........ How can use count clause in above query and display data like as above order ? first display which employee working highest number of contracts ie four and so on.. regards. Mateen |
|
#2
|
||||
|
||||
|
You would have to use 2 queries.
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > count clause in sql query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|