I am doing some data quality checks. Flag 2 needs COUNT(). How could I structure this query So that I can keep the other flags and get my agg fn flag?
WITH
OrderTable AS(
SELECT
order_id, product_id, country, bought_date, price
FROM clothes_items
UNION DISTINCT
SELECT
SELECT
order_id, product_id, country, bought_date, price
FROM decor_items)
SELECT
orderTable.order_id,
IF(product.price < 0.000001, orderTable.product_id, NULL),
AS PriceFlag, //Flag 1
IF(COUNT orderTable.order_id > 1,order_id,NULL) orderDateFlag //Flag 2
FROM Ordertable
LEFT JOIN productTable
ON orderTable.product_id = product.product_id;
will be a few agg fns and a few more non agg calcs so ideally a solution that would enable this. Thanks in advance. Even high level would be helpful, I want to write it in the most efficient way