I have haunted these forums always looking for tips on Joins and Sub_queries and have stockpiled solutions but I keep running into something that seems so simple but it eludes me.
The past few days of searching this forum haven't produced my answer.
So, here goes:
I have one table with a key ID, a person's Name, and a field called Status
I need to join this table to itself with the usual alias and simply present rows .
SO FAR I CAN GET either the Correct Count on 'Appointments' or the Correct Count on 'Fails' but my JOINS can't put it all together so that it looks complete as illustrated below:
id | name | Appointments (from Status values) | Fails (from Status values)
36 | Brad Jones | 78 | 37
45 | Shirley Atwater | 56 | 44
47 | Jack Brill | 33 | 60
53 | Norm Johnson | 17 | 26
I can get one column of the id, one of the name, one from the Status value that is the Count of the Appointments Having 'Appointment' AS # Appointments or I can get the Count of the Status column rows where Status LIKE 'No Interest' but I can't get the Join
I use queries like this and many variations to get 3 columns out of 4 but when I move beyond to try Joins I lose my way.... so here I back up and just show a Query which can be used to either get the number of Appointments or by changing the status value can get the count of Fails....
SELECT trainerid, trainername, COUNT(*) AS Appointments
FROM trainer_appointments
GROUP BY status, trainerid
HAVING status = 'Appointment'
ORDER BY Appointments DESC
in this table each 'name' has a key id number so Brad Jones will always be id 36
I am counting how many rows marked with his id number fulfill the conditions of Status with value 'Appointment' and in a separate column counting Status values with 'No Interest' as FAILS
And I have also tried -- HAVING Status LIKE 'Appointment' or
WHERE Status LIKE 'Appointment' or
HAVING Status = 'Appointment'
When I go further with this query and try to JOIN this table under an alias for itself to get the FAILS COUNT WHERE "Status LIKE 'No Interest'" GROUP BY id, the Join flops.
The JOINS fail with a Variety of Reasons for the Errors out, or the query produces the wrong count.
I have tried adapting many other joins I have seen on this forum to this simple problem but I can't get the correct values even when the query does technically execute.
I would be thrilled if one of you Professionals would show me just how Easy this is!