I have a SQL aggregate function that will get data for every unique normalised_brand, everything works except for my field 'brand_gap', in this query, the brand 'Richell' has 5 results, each result has the brand_gap column set to equal a string 'no', how can I get a single string result from the brand_gap column in my aggregate function?
SELECT
normalised_brand,
COUNT(DISTINCT merch1) merch1_distinct_count,
COUNT(DISTINCT category_level_1) category_level_1_distinct_count,
COUNT(*) product_distinct_count,
CONCAT(CAST(MIN(effective_price) as varchar(10)),' - ', CAST(MAX(effective_price) as varchar(10))) price_range,
null amazon_choice,
CAST(ROUND(COALESCE(AVG(rating),0),2) as varchar(10)) rating,
CAST(COALESCE(SUM(review_count),0) as varchar(10)) review_count,
SUM(CAST(questions_count AS INTEGER)) Q_and_A
-- CONCAT(CAST(brand_gap as varchar(10)),' - ') brand_gap,
-- FIRST (brand_gap)
FROM
"scoring"."final_data"
WHERE
product_gap = 'yes'
AND store_name = 'petco'
AND normalised_brand = 'Richell'
GROUP BY
normalised_brand
So the brand_gap column will always have one value for all the results, how can I get a single brand_gap value? like pick the most commonly occurring value? or pick a random value? or pick the first results value?
Thanks