[SQL]SELECT vlog.lead_id, vlog.phone_number FROM vicidial_log as vlog GROUP BY vlog.lead_id HAVING( CASE WHEN vlog.status = 'NA' THEN 1 WHEN vlog.status = 'ADC' THEN 1 END ) = COUNT(*) [Err] 1054 - Unknown column 'vlog.status' in 'having clause' The query above is not working. I am trying to achieve this: https://www.db-fiddle.com/f/ej4fM8GptBk9FvGJC8AkUH/0 in sense.
[SQL]SELECT vlog.lead_id, vlog.phone_number, vlog.status FROM vicidial_log as vlog GROUP BY vlog.lead_id HAVING( CASE WHEN vlog.status = 'NA' THEN 1 WHEN vlog.status = 'ADC' THEN 1 END ) = COUNT(*) THIS WORKS BUT IT DOESN'T GIVE ME THE RESULTS I WANT
status = can be anything lead_id = not unique phone_number = not unique
I am trying to find phone numbers WHERE atleast the status is either
ADC NA OR BOTH ADC AND NA Any other combination should not return the phone number.
countaggregate from thehavingclause.mysqlallows this syntax in your 2nd example, but could return misleading results. It should behaving count(case....