I have data in two tables that i need to join and return the count of occurences of a record in one of the tables,
The data in Employee table looks like,
empId workpatternId
1 20
The data in the workPattern tables looks like,
workpatternId monday tuesday wednesday thursday friday saturday sunday
20 ALL ALL ALL ALL NULL NULL ALL
The following query should return 5, which is the count of ALL, but returns 7 instead,
SELECT empId,b.workingPatternId, COUNT(monday='ALL') +
COUNT(tuesday='ALL') + COUNT(wednesday='ALL')+ COUNT(thursday='ALL') +
COUNT(friday='ALL')+ COUNT(saturday='ALL')+ COUNT(sunday='ALL') AS COUNT
FROM workPattern b
join Employee e on (e.workpatternId = b.workpatternId) and e.empId = 1
GROUP BY empId ;
what is wrong with the query?
EDIT