s = '''FROM clinics INNER JOIN clinic_drug on clinics.clinicId = clinic_drug.clinicId
WHERE clinic_drug.amount = 0
GROUP BY clinics.name;'''
import re
pattern = re.compile(r'WHERE[.\s\t]*(GROUP BY|;)')
text = pattern.findall(s)
print(text)
re.compile(r'WHERE(.+?)(GROUP BY|;)', re.S)