I'm attempting to write the following MySql query in CI Active Records. The query uses a sub query though and I'm struggling with this.
The query in question:
SELECT
COUNT(*) AS no_skus,
pd_vendor AS brand,
(SELECT COUNT(DISTINCT(pd_model_code))
FROM product_data
WHERE pd_vendor = PD.pd_vendor ) AS unique_models
FROM product_data PD
GROUP BY pd_vendor
ORDER BY
COUNT(*) DESC";
Could anyone suggest how this could be written/structured as a CI Active Record. Thanks