MySQL LIKE IN()?

A REGEXP might be more efficient, but you’d have to benchmark it to be sure, e.g.

SUM OVER PARTITION BY

You could have used DISTINCT or just remove the PARTITION BY portions and use GROUP BY: Not sure why you are dividing the total by the count per BrandID, if that’s a mistake and you want percent of total then reverse those bits above to:

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)