|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Query - General - Count 2 different criteria
Hi,
I am looking for someone to point me in the right direction. I need a query that will count 2 different criteria from a table and then show grouped results. I can group by College and get 1 set of results OK (either 'No of Pupils' OR 'No of Teachers'), but not both with one statement. Imagine tables: CollegeID, CollegeName 0 , Kings 1 , London 2 , Manchester 3 , Salford SubjectID, Name, College, Role, Subject 0 , John, Kings, Pupil, Geography 1 , John, Kings, Pupil, Maths 2 , Nick, Kings, Pupil, English 3 , Peter, Salford, Pupil, Maths 4 , Bill, Kings, Teacher, Maths 5 , Jim, London, Teacher, English I want a result which looks like this: College ! No of Pupils ! No of Teachers Kings ! 3 ! 1 London ! 0 ! 1 Manchester ! 0 ! 0 Salford ! 1 ! 0 ++++++++++++++++++++++++++++++++++++++++ Total ! 4 ! 2 Thanks in advance for any help. Regards, Dave |
|
#2
|
|||||
|
|||||
|
Try something like the following query
SQL Code:
Note, I can see no need for first table at all. Your second table has lots and lots of duplicate data as -- why do you have college name in table2 where it should be the CollegeID?
__________________
Wolffy ------------------------ Teaching people to fish. |
|
#3
|
|||
|
|||
|
Wolffy,
Thats a great help. It opens up a number of options for me. The 1st table is to ensure all Colleges would be shown even if no data was present in table 2. I agree with the redundancy in table 2. If is actually a table I put together as an example of what I am trying to achieve. I never used my real database as the college analogy would be easier to understand than the tables and process I'm trying to work with. Hope this makes sense and thanks again. Dave Pick Quote: |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Query - General - Count 2 different criteria |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|